Copyright: (C) Bennet-Tec Information Systems


MetaDRAW Control
MetaDRAW  - Object Oriented Image Control

The MetaDRAW Custom Control is a Object Oriented Image Display and Manipulation control.

MetaDraw creates and edits pictures represented as a set of graphical elements, manipulates them programmatically, loads and saves the whole picture or any part of it as metafile or bitmap.

MetaDraw is great for HyperGraphics, allowing you to tag individual graphic elements, assigning a "hotspot" identifier, and generating events when clicked.

About the product

Who are we ?

Distribution note

List of VBX'es from Bennet-Tec

Reference

General

Properties

Events

Methods

Conversion Methods

API functions

Techniques

Creating a new picture

Scrolling and Displaying a picture

Editing a picture

Printing with MetaDraw

Using Hot-Spot abilities

Drag-and-Drop operations

Other

Trappable errors

Error messages

Metafile restrictions


Distribution Notes on MetaDRAW VBX Control
Distribution Notes

This product is distributed with the following files:

METADRAW.VBX	design time (full) version of the Custom Control

METADRAW.HLP	This help file

METADRAW.BAS	VB definitions of constants and API functions

METADRAW.LIC	License violation file

BTDESIGN.DLL	Design time and help support library

SAMPLES\	Another sample programs for the VBX MetaDRAW

When you create and distribute an application that uses the VBX MetaDRAW control you should redistribute METADRAW.VBX with your application and install it in the user's Windows\System directory or any other directory where DLLs can be found. The METADRAW.HLP, METADRAW.LIC and BTDESIGN.DLL files are required at design time only. They need not and MAY NOT be redistributed.

Only the REGISTERED users may have and use the design time files METADRAW.LIC and METADRAW.HLP on their computers.


Features of the MetaDRAW VBX Control
MetaDRAW Custom Control General Description

MetaDRAW is an incredibly powerful and flexible control.  Using metafiles as the primary image format, MetaDraw can handle complex tasks like image editing, presenting information in a graphical format, allowing users to drag objects around on the screen, creating hypergraphic data interfaces, and more. The internal picture consists of a set of graphical elements: lines, rectangles, polygons, texts, bitmaps, etc. All Windows graphical primitives are supported. A picture assigned to the MetaDRAW control box is converted into this internal graphical format. After this conversion, the picture can be painted and edited. During editing, the user can change position, size, colors and other attributes of graphical objects, delete objects and add new objects using the mouse or Visual Basic statements.

The list below shows some useful features of MetaDRAW:

∗	Scrollable/Zoomable Image viewer. The picture loaded into the box is scalable. You can specify the visible picture size different from its original size and the picture will be stretched or condensed accordingly. If the picture size is larger than the visible area of the control, the picture can be scrolled in different ways: by dragging with mouse, by using scrollbars or programmatically.

∗	Group objects in container.  Any set of objects can be grouped into a container. The container is one kind of objects and it has all objects' properties.

∗	Programmatic Manipulation - MetaDraw allows the application to control and manipulate the image - anything an end user could do, can be done programmatically.

∗	Merging of images from multiple sources.

∗	Picture type conversion. By setting the PictureType property, the user can convert an editing picture or any part of it to a specified format. This feature is most useful for converting metafiles into bitmaps of a given size or icons.

∗	Printing - MetaDraw can print a complete image or individual elements to a specified device. The user can even print a picture on the Desktop or in another window.

∗	Drag-and-drop - Both File Manager and VB drag-and-drop techniques are both supported.  Of course you can drag individual elements of the control as well.

∗	HyperGraphics applications. The MetaDRAW control has events and API functions specifically designed to support hypergraphic applications. For example, MetaDRAW generates events when objects are clicked on, thus providing "hot spot" capatibility for hyper-graphics application.

∗	Make animations. Programmatically moving objects is a great way to create animated pictures.


Picture's coordinates descriptions
Picture's coordinates

There are three pairs of properties associated with the picture itself. They are determined when the picture is created and cannot be changed afterwards.

PicLeft	PicTop
PicWidth	PicHeight
OrigWidth	OrigHeight

Logical (or picture) coordinates (PicLeft/PicTop and PicWidth/PicHeight) specify the units to be used in Windows output functions. These coordinates don't depend upon the device context and don't have an influence on picture placement and size. They are determined by the PicLeft, PicTop and PicWidth, PicHeight properties accordingly. PicLeft and PicTop determine the offsets of the picture when it is inserted into another one. They are represented by integers ranging from -16384 to 16383 (usually they are zero). PicWidth and PicHeight determine the picture resolution and they are always represented by positive integers ranging from 1 to 16384. The larger the values of these properties, the better the resolution. Compare the next two pictures:

All objects' coordinates in the picture are specified in logical units ranging from (PicLeft, PicTop) to (PicLeft+PicWidth, PicTop+PicHeight).

Original size properties OrigWidth and OrigHeight determine the size assumed to be "normal" when the picture is displayed or printed. This size is explicitly specified at creation time, and is not related to the logical units. The original size is measured in units, specified by the container's scaling mode.


Control's dimensions descriptions
Control's dimensions

There are three pairs of properties specifying the size and position of the control.

Left, Top
Width, Height
ClientWidth, ClientHeight

The Left/Top and Width/Height properties are standard. They determine the position and the size of the control inside its container. The ClientWidth/ClientHeight properties are additional. They can be used to query the actual size of the MetaDraw's client area (without borders and scroll bars).


Picture position inside the control
Picture's visible position and size

The following properties determine the current (visible) size and position of the picture inside the MetaDraw control. They can be changed at any time to zoom or to scroll the picture.

PicXOfs, PicYOfs
PicXSize, PicYSize

These properties are measured in the units specified by the container's scaling mode.


Picture scrolling by mouse or VB code statement
Scrolling and Displaying a picture

The MetaDraw control allows you to display a picture that has been defined in the Picture property. The picture can be displayed in various positions and sizes. The PicXSize, PicYSize properties determine the visible size of the picture, in units specified by the parent control's scaling mode (twips by default). The offset properties (PicXOfs, PicYOfs) are used to determine the position of the picture inside the MetaDraw control box. When PicXOfs, PicYOfs are zero the left-upper corner of the picture will be placed in the left-upper corner of the client area. PicXOfs, PicYOfs and PicXSize, PicYSize are independent.

Depending on the setting of the ScrollBars property, MetaDraw will display scrollbars either all the time, never or only as needed (If visible size of the picture is larger than the size of the window client area in either horizontal or vertical dimentions) . The ScrollBars property may be set to BAR_NONE (0), BAR_AUTO (1) or BAR_ALWAYS (2).

You can scroll the picture or change its position at run-time in any of the following ways:

∗	By programmatically changing values of the PicXOfs, PicYOfs properties

∗	By manually clicking or dragging the scroll bars

∗	By manually dragging within the image (with the Right mouse button). Press and hold the RIGHT mouse button, drag the picture in the control, then release the button. This feature can be disabled by setting the ScrollMouse property.
The cursor [image] appears while you are dragging the picture.

∗	By manually using the keyboard. Hit the cursor keys to scroll the picture horizontally or vertically. This is possible only when the MetaDraw control has focus and the ScrollKeyboard property is True.

MetaDraw gives you an easy way to display the picture by using the AutoScale property. You can display the picture in its original size (SCALE_ORIG), fit it inside the MetaDraw box preserving its aspect ratio (SCALE_FIT), or scale it so that it will always cover the whole MetaDraw window (SCALE_RESIZE).

The Scroll event will occur after any changes in the picture's position or size, regardless of how they were changed. Also, the picture will be automatically updated after any changes of the PicXOfs, PicYOfs and PicXSize, PicYSize properties.

When no picture is defined in the MetaDraw control box, the entire client area of the control will be filled with the color specified by the PicBorderColor property.


How to create a new picture
Creating a new picture

The MetaDraw control operates on the picture referenced by the Picture property. That is, all operations for creating, deleting, and changing objects are applied only to this picture. Usually, this picture is determined at design time by specifying the picture's coordinates properties or by assigning a picture to the Picture property.

To create an empty picture with your own attributes at run time, execute these steps:

1.	Destroy the old picture by:
    MDraw.PicWidth = 0     ' or
    MDraw.PicHeight = 0

2.	Set all the properties required to specify the logical units (PicLeft, PicTop and PicWidth, PicHeight) and the actual size (OrigWidth and OrigHeight) for the picture being created.

3.	Create a new empty picture with the specified attributes in one of the following ways:
    MDraw.Picture = LoadPicture()   ' or
    MDraw.Clear

Following these steps, an empty picture will be created. You can use the AddItem method or mouse editing tools to create and edit new objects.

You can also initialize the picture by assigning a picture to the Picture property:

MDraw.Picture = PicBox.Picture            ' or

MDraw.Picture = LoadPicture("SOMEPIC.WMF")

In this case, the picture's coordinates will be set according to the picture loaded. Also, you can create a new picture with an image that is saved in the PictureImage property using the Action property (ACT_IMAGEPICTURE or ACT_IMAGESWAP).


How to edit a picture
Editing a picture

The MetaDraw control has several built-in tools for editing the picture. You can add new graphic elements, merge pictures, delete parts of the picture, move objects around or change their attributes (size, colors, etc.).

All editing operations are performed only on the picture specified by the Picture property. Also, you can edit only one part of the picture (the currently open container) at a time.

Creating a new object using the AddItem method

Creating a new object using the mouse

Insert an external picture

Selecting objects

Editing objects

Deleting objects

Grouping and ungrouping objects

Changing object's attributes

Rotating an object

Flipping an object

Changing the layering order


Printing a picture with MetaDraw
Printing with MetaDraw

MetaDraw allows the picture to be printed in any size at any location on the printed page. The picture can be merged with any other printable information using the Printer object. You can also draw the picture, or any part of it, in any window whose device context (hDC) you know.

The properties ExportLeft, ExportTop specify the placement of the exported picture on the printer page or on the device's window (in device pixels). The ExportWidth, ExportHeight properties determine the size of the picture.

A picture is transferred to the specified device (printer or window) when the ExportDC property is set to this device context. During objects exporting you can execute the special code for each exporting object using the Export event (for example display a progress indicator).


Using Hot-Spot abilities

One of MetaDraws really outstanding features (ok, so we're not so modest) is it's support for "hot spots". You can assign a picture (any bitmap or metafile) to the MetaDraw control, then determine several invisible objects and declare them as hot spots. When you are dragging the mouse pointer over these objects, or click the left mouse button on one of them, special events will be generated.

For example, you can create a picture of a world map, and declare each continent as a hot spot by changing ObjHotSpot property for each object or container (if the continent is made up of several objects). Then, you can determine the actions to take in the OnHotSpot and HitObject event (e.g., display the detailed information about the continent pointed by the user).


Using drag-and-drop operations
Drag-and-Drop operations

The MetaDraw control supports the drag and drop technology of Windows 3.1 and dragging and dropping controls in Visual Basic.

One or more files selected in the File Manager can be "dragged" by the mouse to a given location inside the MetaDraw control box and "dropped" into it.

When the file names are dropped on the MetaDraw control, the DropFile event is fired. Depending upon the DropMode property setting, it is fired for every dropped file or only for the first file in a group of dropped files. If DropMode is zero, files are not allowed to be dropped into MetaDraw's window.

Note	There is no default processing for dropped files, only the event is fired. To process the files, put code in the DropFile event.

Using the following standard drag-and-drop properties, events, and methods, you can specify both the meaning of a drag operation and how dragging can be initiated for the control.

Category	Item	Description

Properties	DragMode	Enables automatic or manual dragging of the control.

DragIcon	Specifies what icon is displayed when the control is dragged.

Events	DragDrop	Recognizes when a control is dropped onto the MetaDraw control.

DragOver	Recognizes when a control is dragged over the MetaDraw control.

Method	Drag	Starts or stops manual dragging.

For more information about dragging and dropping controls, see the Microsoft Visual Basic Language Reference and Programmer's Guide.


Creating a new object using the AddItem method
Creating an object using the AddItem method

Using this method you can add an object with one of the following types:

Object	Image	Constant

line	OT_LINE

rectangle	OT_RECTANGLE

rounded rectangle	OT_ROUNDRECT

ellipse	OT_ELLIPSE

arc	OT_ARC

sector (pie slice)	OT_PIE

chord	OT_CHORD

polyline	OT_POLYLINE

polygon (freeform)	OT_POLYGON

text	' '	OT_TEXT

image	OT_IMAGE

Use the following syntax of the AddItem method to create a new object:

MDraw.AddItem boundaries$, object_type%

The first parameter is a text string containing four integer values, which specify the desired top/left and bottom/right coordinates of the new objects boundaries. If the empty string is specified, the current open container (or image if object_type% is OT_IMAGE) boundaries are used for the new object. The second parameter is a type of a new object. You can specify it using one of the predefined constants (OT_xxxx). If object_type% is OT_IMAGE (12), the image kept in the PictureImage property will be added as a single object, or as a container if the picture in the PictureImage property contains more than one object.

To add a bitmap, load a bitmap into the PictureImage property and call the AddItem method with the value OT_IMAGE for object_type%.

' Add a bitmap from the file "IMAGE.BMP" with

' (10,20) coordinates for the leftupper corner

MDraw.PictureImage = LoadPicture("IMAGE.BMP")

MDraw.AddItem "10 20", OT_IMAGE

The new object is automatically selected (the old selection is dropped) and the Current property contains the handle of this object. Each object is created with default attributes, including color, line style, and fill style. These attributes can be set before creation by setting the corresponding properties when the Current property has been set to OBJ_CURR_ATTR (4). Use the Text property to specify a text string for a text object after one has been created.

The new object is always added to the top of the object stacking order, which is at the end of object list. After the object has been created you can change its layering order, placement, size and attributes. Use the MD_SetParams() API function to change additional object parameters (polylines points, rounded corners and so on).


Creating a new object using the mouse
Creating an object using the mouse

There are several edit modes for adding new objects that are supported by MetaDraw. They work like similar tools in other applications, such as MS Draw or CorelDraw. These edit modes are determined by the EditMode property.

Constant	Value	Cursor	Action

ED_LINE	1	Draw a line

ED_RECT	2	Draw a rectangle

ED_ROUND	3	Draw a rounded rectangle

ED_ELLIPSE	4	Draw an ellipse

ED_ARC	5	Draw an arc

ED_PIE	6	Draw a sector

ED_CHORD	7	Draw a chord

ED_POLYLINE	8	Draw a polyline

ED_POLYGON	9	Draw a polygon

ED_TEXT	10	Add a text object

ED_ADDIMAGE	12	Add an image

To create an object, assign the EditMode property to the mode for required object. The mouse cursor's appearance will change for each mode (see table). Then, press the left mouse button and drag the mouse to draw the object. A new object will be added after the left mouse button is released.

If the EditMode property is set to ED_TEXT, an empty text object will be created and the cursor caret will appear, ready to accept characters from the keyboard. In that case, using mouse you can specify a characters' size and a rotation angle (only for TrueType fonts). A single mouse click will add a new text object with the current attributes (size and orientation).

When the EditMode property is set to ED_POLYLINE or ED_POLYGON, you can drag the mouse to create freeform shapes. Click the right mouse button (don't release the left button) to create straight line segments.

During mouse dragging, you can hold down the following keys:

SHIFT	Allows you to add an object with equal sides. Hold down this key if you want to create a circle or a square or prevent the change of an aspect ratio of image.

CTRL	Toggle Snap-to-Grid effect. The current mouse coordinates will be pulled into alignment with the nearest intersection of grid lines during the drawing of an object. Holding down this key enables snap-to-grid effect for polyline and polygon and disables it for other objects.
For the text object, holding down this key allows you to determine orientation of the text string (a rotation angle).

The Current property will contain the handle of the new object. This object becomes selected, and old selections are dropped.


Merging with external pictures
Inserting an external picture

A way to insert objects into the current picture is using the PictureClip property. After assigning a picture to this property, the specified picture is converted to the internal format corresponding to the object or container (if it contains more than one object). This object is inserted into the current picture according to its offset coordinates and physical sizes. If the new object does not fit in the current picture, it is shrunk.

You can use the MD_SetBounds() or MD_MoveObjects() API functions to change the object coordinates (placement and sizes).

Moreover, a new object (image) can be inserted from PictureImage using the Action property with ACT_IMAGEINSERT value.


How to select an object
Selecting objects

You can select an object in one of the following ways.

Programmatically

To change an object's selection status, set the Current property to a handle of the object to be selected or dropped from selection. Then, assign the ObjSelected property the value True to select object or False to drop selection.

If Current is OBJ_CONTAINER, all objects in the current open contained will be selected or dropped from selection.

Note	You can only select objects that are in the objects list of the current open container.

Using the mouse

Switch to selection mode to select objects using the mouse. To do this, assign the EditMode property value ED_SELECT.

To select a single object, click the left mouse button on an object. The selection of all other objects will be dropped. For multiple selection, hold down the SHIFT key while you click each of the objects you want to select.

To select several objects at the same time, click the left mouse button outside any object, then drag the mouse to create a rectangle enclosing all the objects you want to select. All objects that are completely placed inside this rectangle become selected. If you do this process while holding down the SHIFT key, objects with any part inside the rectangle will be selected.

To cancel the selection of objects, do one of the following:

∗	To cancel the selection of some of the selected objects, hold down the SHIFT key and click the left mouse button on the object(s) you want to deselect.

∗	To cancel the selection of all selected objects, click the left mouse button outside any objects


Moving and resizing objects
Editing objects

You can edit any newly created objects, and old objects from a loaded picture programmatically (using VB statements) or using the mouse.

You can change an object's placement and resize it programmatically using the MD_SetBounds() and MD_MoveObjects() API functions.

It is easy to edit objects using the mouse. To do this, set the EditMode property to ED_SELECT. In this edit mode, you can:

∗	Select objects

∗	Move the selected object or group of objects. Select the object(s) you want to move, click the left mouse button on one of the selected objects and drag the object(s) to the new location. Note that this can be disabled in the EditFlags property. During the dragging object(s), you can hold down the CTRL key to disable alignment to grid.

∗	Resize an object. Select the object you want to resize (click the left mouse button on it), then click the left mouse button on one of the special markers and drag it. Note that this can be disabled in the EditFlags property. During dragging marker you can hold down the CTRL key to disable alignment to grid.

∗	Change the object's additional parameters (like rounded corners, sector's start and end points, reshaping a polyline or polygon). Double-click the left mouse button on the object you want to edit (markers will apear). Drag a marker to change the object's shape. If you have double-clicked the left mouse button on a container, it is "opened" and you can edit objects inside it (this feature can be disabled in the EditFlags property).


How to delete an object
Deleting objects

To delete an object, specify its handle in the Current property and call the RemoveItem method:

MDraw.RemoveItem

To remove several objects, select the objects you want to delete, then call the RemoveItem method with parameter OBJ_SELECTED:

MDraw.RemoveItem OBJ_SELECTED

To delete all objects in the open container, use the following call:

MDraw.RemoveItem OBJ_CONTAINER

After that call, all objects will be deleted (including the container) and the parent container is opened.

Note	You can only delete object(s) that are in the objects list of the open container.


Grouping and ungrouping objects

The MetaDraw control allows you to unite several objects into one container. You can use a container when you want to manipulate many objects as a unit. After several objects are grouped into a container, you can move and resize them together as a single object.

To group several objects, select them, then assign the value ACT_GROUP to the Action property. This creates a new object (container) and inserts it after last selected object (in the objects list) . All selected objects will be moved into the container. The new container becomes selected.

To ungroup a container, specify its handle in the Current property and assign the value ACT_UNGROUP to the Action property. All objects from this container will be moved up one level in the objects list (after ungrouping the container) and the empty container will be removed. You can ungroup many containers at once. Select several containers you want ungroup, and specify these selected objects in the Current property (OBJ_SELECTED). Then, apply the action ACT_UNGROUP.


Changing object's attributes

To change the attributes of an object, specify its handle in the Current property and assign new attributes to corresponding properties (LineColor, FillColor, FillStyle, DrawMode, etc.). If the specified object is a container, then the specified attribute is set for all objects of this container.

You can change one attribute for several objects using one assignment. To do this, select the required objects, set the Current property to OBJ_SELECTED and set corresponding attribute property to a new value.


Rotating an object

You can rotate an object to the right or to the left in 90° increments. You can not rotate bitmaps or texts objects (however, you can specify an orientation for a text object at the time it is created). If you rotate a text object or a bitmap, the box (boundary) rotates, but the text or the image inside it remains unchanged.

To rotate an object specify its handle in the Current property and assign the Action property with one of the following values:

ACT_ROTATELEFT	- To rotate object in a clockwise direction

ACT_ROTATERIGHT	- To rotate object by a counter clockwise direction

If the Current property specifies several objects (OBJ_SELECTED or OBJ_CONTAINER), all objects will be rotated independently.


Flipping an object

You can create a mirror image of an object by flipping it. You can not flip text objects.

To flip an object specify its handle in the Current property and assign the Action property with one of the following values:

ACT_FLIPHORZ	- To flip object(s) horizontally

ACT_FLIPVERT	- To rotate object(s) vertically

If the Current property specifies several objects (OBJ_SELECTED or OBJ_CONTAINER values) all objects will be flipped independently.


Changing the layering order of objects

You can move an object in back or in front of other objects in the objects list.

To change the layering order of one or more objects, specify its handle in the Current property and assign to the Action property one of the following values:

ACT_SENDBACK	- Send specified object(s) to the back of all other objects

ACT_MOVEFRONT	- Bring specified object(s) to the front of all other objects

ACT_ONEDOWN	- Move object(s) before previous object

ACT_ONEUP	- Move object(s) after next object

If the Current property specifies many selected objects (OBJ_SELECTED), then after assigning ACT_ONEDOWN or ACT_SENDBACK, all selected objects will be removed from the objects list (keeping with its stacking order). Then, they will be inserted before first object in the objects list (ACT_SENDBACK) or before the object in the list which is before first selected object (ACT_ONEDOWN).


Types of the objects
Type of the objects

The image held in the MetaDraw control consists of a set of graphical elements. Each graphical elements is an distinct object stored in the MetaDraw control in a special internal format. The MetaDraw control supports the following graphical objects:

Object type	Constant	Value	View

container	OT_CONTAINER	0

line	OT_LINE	1

rectangle 	OT_RECTANGLE	2

rounded rectangle 	OT_ROUNDRECT	3

ellipse	OT_ELLIPSE	4

arc	OT_ARC	5

sector (pie slice)	OT_PIE	6

chord	OT_CHORD	7

polyline	OT_POLYLINE	8

polygon (freeform)	OT_POLYGON	9

bitmap	OT_BITMAP	10

text	OT_TEXT	11	A text

image	OT_IMAGE	12


Reserved object's handles
Reserved objects handles

The following special object's handles is used to assign to the Current property to specify a group of mostly used objects.

Constant	Value	Description

OBJ_CONTAINER	1	Specifies all objects in the current open container.

OBJ_SELECTED	2	Specifies all selected objects.

OBJ_SEL_ATTR	3	Specifies all selected objects and global MetaDraw object's attributes for getting/setting attribute operations.

OBJ_CURR_ATTR	4	Specifies global MetaDraw object's attributes for getting/setting operations.

OBJ_CONT_MAIN	5	Specifies the Main Container.

OBJ_SEL_ATTR and OBJ_CURR_ATTR are valid only for getting or setting attributes of an object (like LineColor, Text, BackStyle, DrawMode). When the Current property is OBJ_SEL_ATTR, and you read attribute properties, then it returns the value of a specified attribute of the objects if they are equal. Otherwise it returns the corresponding attribute from the global object's attributes.


Objects

The image held in the MetaDraw control consists of a set of graphical elements such as lines, rectangles, polygons, texts, bitmaps, and containers. Each graphical elements is an distinct object stored in the MetaDraw control in a special internal format.


Container

Several objects can be grouped into a container. You can move and resize a container as an object. The complete image held by MetaDraw is itself a container holding all the graphical elements within the picture.


Layering order of objects

All objects inside a MetaDraw container are held in a list. As objects are added to a MetaDraw image they are appended to the end of that list. When the picture is repainted, they are drawn from the bottom most object up to topmost one. Therefore, objects that are added later will generally be drawn on top of previously drawn objects. An object's position in the list (and thereby the visible layering of the objects) can be modified by appropriate setting of the Action property.


Open container

A container (grouping of objects) can be put into another container; it is possible to have nested levels. The MetaDraw control allows the user to edit objects only for one container (one level) at a time. In other words, the open container is the container where editing operations are allowed. New objects will also be added to this open container.


Current object(s)

To access an object you should use the Current property. This property contains a handle of the object, or the group of objects, that are being used in some actions. You should assign an object handle to this property before performing any manipulations. You can assign some reserved handles to the Current property to specify a group of mostly used objects.


Selection markers

The selection markers are useful for resizing objects, to change object's shape or to mark the selected objects. A selected object is displayed with special markers (small rectangles at the corners of the boundaries). The selection markers can be hidden by setting the MarkerSize property to zero.


Windows metafile

A MetaFile is a special graphic format for vector based images.  MetaFile images take up very little memory compared to Bitmaps.  They are resolution- and device-independent. Most importantly, MetaFiles are made up of individual objects which can be individually moved, displayed, even tagged using the proper tool - such as MetaDraw.


Trappable errors

A number of trappable errors can occur during the operation of MetaDraw. If you do not trap these errors, your application will close after displaying an error message. You can use the standard Visual Basic Err function to test which error has occurred, as shown in the following example:

On Error Goto E1

 . . .  (some action involving MetaDraw)

Exit Sub

E1:	Select Case Err

  Case MDERR_INVALIDHANDLE

   . . .  (code for recovering from error)

End Select

For more information about trapping errors in Visual Basic, see the Visual Basic Programmers Guide.


Metafile conversion restrictions
MetaFile Restrictions

The MetaDraw control operates with graphical objects which are determined by the special internal format. It needs to convert metafile records into corresponding objects. Usually, there are no problems during the transformation, however the MetaDraw control has some restrictions for converting a metafile into its own internal format:

1.	If there are a few records for META_SETWINDOWORG and META_SETWINDOWEXT in the metafile, only first pair will be accepted. The picture can be distorted if the metafile contains more than one records META_SETWINDOWORG or META_SETWINDOWEXT

2.	The META_SETVIEWPORTORG, META_SETVIEWPORTEXT records are ignored. If these records are present in the metafile then the resulting picture can be distorted.

3.	A value of the META_SETMAPMODE record is used only to determine the physical sizes of the picture (if they were not specified in the metafile header).

4.	All records which specify a clipping region (like META_INTERSECLIPRECT, META_SELECTCLIPREGION and so on) are ignored.

5.	Records which work with regions (META_FILLREGION, META_FRAMEREGION and so on) are ignored.

6.	Records which fill an area of the screen surface (META_FLOODFILL, META_EXTFLOODFILL) are ignored.

7.	Records which work with logical palette (META_REALIZEPALETTE, META_RESIZEPALETTE and so on) are ignored.

8.	MetaDraw works only with polygons in ALTERNATE polygon-filling mode. Therefore, the record META_SETPOLYFILLMODE is ignored.

9.	The text which is specified by META_DRAWTEXT (DrawText function) is converted to a one line text string. All text objects will be drawn using the ExtTextOut() GDI function.

10.	Device-dependent bitmaps that are drawn by META_BITBLT, META_STRETCHBLT records will be converted into DIB using the current realized palette.

The coordinates which are specified in the metafile record will be used for creating the corresponding object. The boundary of the new picture is the smallest rectangle which contains the boundaries of all objects. The picture logical coordinates (like PicLeft, PicTop, PicWidth and PicHeight) are calculated as an intersection of this rectangle and the rectangle determined by the META_SETWINDOWORG and META_SETWINDOWEXT records.

The MetaDraw control supports the extended metafile format (using META_ESCAPE records), which allows you to save additional information about objects (objects flags, container structure, tag information, ...). You can export a metafile without additional information by setting the PictureType property to the value PICTYPE_PLAINWMF.


Error messages and constants
Error messages

The following table lists the trappable errors for the MetaDraw control.

Error#	Constant	Message and Explanation

387	VBERR_CANTSETPROP	??? property cant be set on this control
This is a standard Visual Basic error. It occurs when you attempt to change one of the properties which are generally writable, but not in this particular state of the given control.

24000	VBERR_NOSELECTION	There are no selected objects
You are trying to invoke an action which requires objects to be selected (e.g. grouping objects), but no objects are selected.

24001	VBERR_INVALIDHANDLE	Invalid object handle
The handle specified in the Current property is not a valid object handle or the Current property contains one of the reserved handles which are not allowed for the implemented action.

24002	VBERR_INVALIDTYPE	Invalid object type
The second parameter of the AddItem method does not refer to a valid object type.

24003	VBERR_INVALIDINDEX	Invalid index
An incorrect index was specified in the RemoveItem method or while reading the property ObjCount.

24004	VBERR_INVALIDPARAM	One or more parameters are invalid
Parameters passed in the MD_SetParams() API function are not applicable for the Current object.

24005	VBERR_BADMETAFILE	Metafile format error
The MetaDraw control found a bad metafile record during conversion of the metafile into the MetaDraws internal format.

24006	VBERR_NOTCONTAINER	Object is not a container
The Current property does not contain a handle of a valid container. For example, you are trying to set the Current pointer to the first child of the container by assigning the ObjMove property to MOVE_CHILD_FIRST, but the Current property did not contain either the reserved handle OBJ_CONTAINER or a handle of the container.

24007	VBERR_NOTTEXT	Object is not a text
You are attempting to make an action which is allowed only for Text objects. For example, you have assigned a text string to a Polyline object.

24008	VBERR_NOPICTURE	Picture was not defined
A picture was not defined in the PictureImage property when image operations were invoked (e.g. insert image to the current picture using AddItem method with OT_IMAGE parameter).

24009	VBERR_CANTDELETE	Object can not be deleted
You are trying to delete the main container in the RemoveItem method. The main container cannot be deleted, but you can delete all objects in the main container using the Clear method.

24010	VBERR_CANTOPEN	Object can not be opened
You are trying to open an object that cannot be opened by assigning True to the ObjOpened property. Only the following objects can be opened: Container, RoundedRectangle, Arc, Pie, Chord, Polyline, Polygon.


Properties of the MetaDRAW VBX
Properties of the MetaDRAW Control

Properties of the MetaDraw control can be divided into several groups. There are picture, general control, and properties that are used for object manipulating. These groups of properties are listed below.

Standard properties

Align	BorderStyle	DragIcon	DragMode	Enabled	Height	HelpContextID	hWnd	Index	Left	Name	Parent	TabIndex	TabStop	Tag	Top	Visible	Width

Picture information properties

OrigWidth	OrigHeight	PicLeft	PicTop	PicWidth	PicHeight	PicXOfs	PicYOfs	PicXSize	PicYSize

Display properties

AutoScale	GridShow	GridAlign	GridWidth	GridHeight	MarkerSize	OpenDraw	PicBackColor	PicBorderColor	Redraw	Repaint	ScrollBars	ScrollCheck	ScrollMouse	ScrollKeyboard	ShowInvisible

Mode properties

DropMode	EditMode	EditFlags	EventMask	HotSpots	MouseCursor	MousePointer

Export/Import properties

Picture	PictureChanged	PictureClip	PictureImage	PictureType	ExportLeft	ExportTop	ExportWidth	ExportHeight	ExportDC	hDC	hPal

Object properties

Action	Current	ObjMove	ObjCount	ObjNumber	ObjTag	ObjType	ObjVisible	ObjHotSpot	ObjHitable	ObjSelected	ObjOpened	ObjLeft	ObjTop	ObjRight	ObjBottom

Generic object attributes

DrawMode	BackStyle	BackColor	LineColor	LineStyle	LineWidth	FillColor	FillStyle	FillPattern

Text object attributes

FontBold	FontItalic	FontSize	FontStrikethru	FontUnderline	FontName	FontOrient	FontStyle

Text	TextColor	TextHAlign	TextVAlign

Coordinates conversion properties

ClientWidth	ClientHeight

ClientToLogicX	ClientToLogicY	LogicToClientX	LogicToClientY

Other properties

[About]	Popup the "About" dialog box


Picture information properties

This group contains properties which describe the logical picture coordinates, the original picture size and how the picture must be displayed (visible sizes and offsets).

PicLeft, PicTop	Origin of the picture coordinate system

PicWidth, PicHeight	Extent of the picture coordinate system

OrigWidth, OrigHeight	Original picture size

PicXOfs, PicYOfs	Offset of visible rectangle of picture

PicXSize, PicYSize	Size (width and height) of visible picture


Picture display properties
Display properties

This group contains properties which describe attributes of the visual picture box, grid attributes, as well as if the picture must be scrolled.

AutoScale	Determine how picture should be displayed

GridShow, GridAlign	Whether or not to show grid or to align to grid

GridWidth, GridHeight	Specify grid size

MarkerSize	Determines a size of selection markers

PicBackColor,

PicBorderColor	Specify the color to be used as a background inside or outside picture rectangle

ScrollBars	Whether or not to show scrollbars

ScrollCheck	Check bounds after picture is scrolled or resized.

ScrollMouse	Enable or disable picture scrolling by mouse

ScrollKeyboard	Enable or disable picture scrolling by keyboard

ShowInvisible	Whether or not to paint invisible objects

Redraw	Whether or not to redraw picture after any change

Repaint	Specifies as picture should be repainted

OpenDraw	Specifies as pictures elements will be drawn


Picture view and edit mode properties
Mode properties

This group contains the following properties:

DropMode	Determines how the control should handle filenames dropped from the Windows File manager

EditFlags	Specifies mouse functions in selection edit mode

EditMode	Determines a mode for adding a new object by mouse

EventMask	Specifies mask for some events

HotSpots	Determines "hot spot" mode

MouseCursor	Determines the mouse cursor shape

MousePointer	Determines a mouse pointer inside the control


Import and export properties
Import/Export properties

This group contains properties for importing/exporting pictures (or some part of one):

hDC	Imports hDC for painting

hPal	Contains a logical palette handle for loaded picture

Picture	Used to import or export a picture in the control

PictureChanged	Determines the picture changing status

PictureClip	Merge or clip any part of the picture

PictureImage	Determines a picture image

PictureType	Type of the picture for export

ExportDC	Determines a Device context for exporting picture

ExportLeft, ExportTop	Determines X- or Y-coordinate of the origin for exported objects

ExportWidth,

ExportHeight	Determines the dimensions of the area on the destination device


Object's properties
Object properties

This group contains the following properties:

Action	Determines the action on specified objects

Current	Specifies the current object or the group of the objects

ObjMove	Move Current pointer to the specified object

ObjCount	Counts the number of specified objects

ObjHitable	Returns/Toggles the "hitable" flag for specified object

ObjHotSpot	Toggles the "hot spot" flag for specified object

ObjNumber	For conversion objects order number in handle

ObjOpened	Opens the specified object (container)

ObjLeft, ObjTop,

ObjRight, ObjBottom	Return the objects logical coordinates

ObjSelected	Returns/Toggles selection status

ObjTag	Determines the object information string

ObjType	Returns the object type

ObjVisible	Returns/Toggles visible status of the specified object


Genaral object's painting parameters
Generic object attributes

This group contains properties which describe visible attributes of objects.

DrawMode	Determines the painting mode

BackStyle	Determines the background style (transparent or opaque)

BackColor	Determines the background color of an object

LineColor	Determines the color of an objects line or border

LineStyle	Determines the line or border style

LineWidth	Determines the line or border width

FillColor	Determines the color used to fill a shape object

FillStyle	Determines the method used to fill shape objects

FillPattern	Determines the bitmap pattern to fill a shape object


Text object properties
Text object attributes

This group contains properties which describe attributes for text objects.

FontBold, FontItalic, FontStrikethru, FontUnderline, FontSize, FontName

FontStyle	Font style - determines how font size is set

FontOrient	Characters orientation

Text	Determines a set of characters (text string) for the Text object

TextColor	Characters color

TextHAlign	Determines the horizontal alignment for text object

TextVAlign	Determines the vertical alignment for text object


Coordinates conversion properties
Coordinate conversion properties

This group contains properties to convert values between different coordinate systems.

ClientWidth,

ClientHeight	Return the width and height of picture box client area

ClientToLogicX,

ClientToLogicY	Convert point from client box pixels to logical picture coordinates

LogicToClientX,

LogicToClientY	Convert from logical coordinates to client pixels


Action  Property

See Also	Example

Description

Starts specified action on the current objects, or container, specified in the Current property.

Usage

[form.]MDraw.Action = action%

Settings

The Action property settings are:

Constant	Value	Description

ACT_GROUP	0	Create a container grouping all currently selected objects. More than one object must be selected.

ACT_UNGROUP	1	Ungroup container (or all selected containers). After this action all object(s) from the container(s) become selected.

ACT_SENDBACK	2	Send selected objects to the back of all other objects.

ACT_MOVEFRONT	3	Bring selected objects to the front of all other objects.

ACT_ONEDOWN	4	Move object(s) before previous object.

ACT_ONEUP	5	Move object(s) after next object.

ACT_FLIPHORZ	6	Flip object(s) horizontally.

ACT_FLIPVERT	7	Flip object(s) vertically.

ACT_ROTATELEFT	8	Rotate object in a clockwise direction.

ACT_ROTATERIGHT	9	Rotate object by a counter clockwise direction.

ACT_IMAGEINSERT	10	Insert picture specified in PictureImage property to the open container.

ACT_IMAGECOPY	11	Copy object(s) specified by Current property into PictureImage.

ACT_IMAGEPICTURE	12	Create a new picture using the picture that is kept in the PictureImage property.

ACT_IMAGESWAP	13	Swap pictures between the Picture and PictureImage properties. This action works only when pictures are defined both in Picture and PictureImage.

ACT_DUPLICATE	14	Duplicate object(s). MetaDraw adds the new object(s) at the top of objects stack. If the action is applied to selected objects, each selected object will be duplicated and it becomes selected.

Remarks

The Current property specifies the object(s) to be affected by the action (for ACT_GROUP it must always be set to OBJ_SELECTED). After the specified action is done the Current property contains one of the following values:

Action	Value of the Current property

ACT_GROUP	Handle of the new container.

ACT_UNGROUP	OBJ_SELECTED (all selected objects).

ACT_IMAGEINSERT	Handle of the inserted object (or container).

ACT_IMAGEPICTURE,

ACT_IMAGESWAP	Handle of the main container.

ACT_DUPLICATE	Handle of the new object or OBJ_SELECTED (for selected objects).

The Current property is not changed after one of the following actions: ACT_SENDBACK, ACT_MOVEFRONT, ACT_ONEDOWN, ACT_ONEUP, ACT_FLIPHORZ, ACT_FLIPVERT, ACT_ROTATELEFT, ACT_ROTATERIGHT, ACT_IMAGECOPY.

Objects can only be rotated 90° per action. To rotate an object 180°, the action must be applied twice.

Data Type

Integer (Enumerated)


See also

Selecting objects

Changing the layering order

Current property

Picture property

PictureImage property


AutoScale  Property

See Also	Example

Description

Determines whether the picture image is automatically scaled to fit in the display window or the original picture size is preserved.

Usage

[form.]MDraw.AutoScale = setting%

Settings

The AutoScale property settings are:

Setting	Value	Description

SCALE_NONE (default) 	0	The values of PicXSize, PicYSize properties are set according to the original picture size only when the picture is loaded and are not changed automatically afterwards.

SCALE_RESIZE	1	When the control is resized, PicXSize and PicYSize are set to the width and height of the control (without border) accordingly.

SCALE_FIT	2	The PicXSize, PicYSize properties are immediately set such that the image fits in the display window of the MetaDraw control (preserving the pictures aspect ratio). These properties will be updated if control is resized.

SCALE_ORIG	3	The PicXSize, PicYSize properties are immediately set to the actual size of the current picture. After the assignment, the control resets the value of the AutoScale property to 0 (SCALE_NONE). The PicXOfs, PicYOfs properties are immediately set to zero.

Remarks

The setting SCALE_ORIG (3) is more like a command rather than a setting, but it is an easy way to display the picture with its original sizes. The PicXOfs, PicYOfs, PicXSize, PicYSize properties can be changed manually only if AutoScale is SCALE_NONE (0).

SCALE_NONE (0)	SCALE_RESIZE (1)	SCALE_FIT (2)

SCALE_NONE (0)	The visible picture position and sizes are set manually using PicXOfs, PicYOfs and PicXSize, PicYSize properties.

SCALE_RESIZE (1)	The picture fills the whole MetaDraw window area. It can be distorted if the width/height ratio is not the same as the OrigWidth/OrigHeight ratio.

SCALE_FIT (2)	The area that is not covered by the picture will fill with color specified in the PicBorderColor property.

Data Type

Integer (Enumerated)


See also

Picture's position and size

Displaying and scrolling the picture

PicXOfs, PicYOfs properties

PicXSize, PicYSize properties


BackColor  Property

See Also	Example

Description

Determines the background color of an object.

Usage

[form.]MDraw.BackColor [= color_expression&]

Remarks

The BackColor is used to fill a text objects background, gaps in non-solid lines, and the space between hatches in a hatched brush. The BackColor property is ignored if the BackStyle property is zero (TRANSPARENT).

Data Type

Long (Color)


See also

Changing object's attributes

BackStyle property

LineColor property

FillColor property


BackStyle  Property

See Also	Example

Description

Determines whether the objects border or background is transparent or opaque.

Usage

[form.]MDraw.BackStyle [= setting%]

Settings

The BackStyle property settings are:

Setting	Value	Description

TRANSPARENT	0	Background is not changed.

OPAQUE	1	The color specified by the BackColor property is used to fill in the background of a text object's, gaps in non-solid lines and the space between hatches in a hatched brush.

Remarks

All constants for this property are included in the file METADRAW.BAS.

Data Type

Integer (Enumerated)


See also

Changing object's attributes

BackColor property


Client area size
ClientWidth, ClientHeight  Properties

See Also	Example

Description

These properties return the dimensions of the visible area inside the MetaDraw box, in units specified by the parent control's ScaleMode, ScaleLeft, ... properties (which by default are in twips).

Usage

w% = [form.]MDraw.ClientWidth

h% = [form.]MDraw.ClientHeight

Remarks

The visible area is actually the client area of the MetaDraws window. If both the border and the scroll bars are disabled on the control, the ClientHeight and ClientWidth properties have the same values as Height and Width. Otherwise, they will be less by the dimensions of the scroll bars and/or the border.

Data Type

Single


See also

Control's dimensions

Coordinates conversion

AutoScale property


Coordinates conversion properties (methods)
Coordinates conversion  Properties

See Also	Example

Description

The MetaDRAW control has several "array" properties (which look like "methods") to convert between the client and picture coordinates.

Usage

nPicX% = MDraw.ClientToLogicX(nClientX%)

nPicY% = MDraw.ClientToLogicY(nClientY%)

nClientX% = MDraw.LogicToClientX(nPicX%)

nClientY% = MDraw.LogicToClientY(nPicY%)

Remarks

Logical picture coordinates are converted to client pixels using the following expressions:

nClientX% = (npicX% - PicLeft) * PicXSize / PicWidth - PicXOfs

nClientY% = (npicY% - PicTop) * PicYSize / PicHeight - PicYOfs

Where PicXOfs, PicYOfs, PicXSize, PicYSize are converted in the screen pixels.

MetaDraw uses a subscript of an "array" as an input parameter for the conversion function. However, they look like and work like methods.

Note	The client window coordinates are measured in screen pixels regardless of the units specified by the parent control. You can use the parent controls ScaleMode, ScaleLeft, ... properties for converting other units to pixels.

Data Type

Integer


See also

Picture's coordinates

Control's dimension


Current  Property

See Also	Example

Description

This property determines the object, or group of objects, that are being used in the specified action (change objects attributes, move, group objects, etc.).

Usage

[form.]MDraw.Current [= object_handle&]

Remarks

All object-related properties apply to the Current object. You should assign an object handle or one of the predefined scope constants to this property before performing any manipulations with the object(s).

There are some reserved objects handles:

Constant	Value	Description

OBJ_NULL	-1	Refer no objects - can be returned after an action has failed.

OBJ_CONTAINER	1	The current open container.

OBJ_SELECTED	2	All selected objects.

OBJ_SEL_ATTR	3	All selected objects and global MetaDraw objects attributes for getting/setting attribute operations.

OBJ_CURR_ATTR	4	Use global MetaDraw objects attributes for getting/setting operations.

OBJ_CONT_MAIN	5	Specifies the Main Container.

If an action has failed (for example, the user tries to read an objects fill color for some selected objects and they have different colors) this property is set to OBJ_NULL.

OBJ_SEL_ATTR and OBJ_CURR_ATTR are valid only for getting/setting attributes of an object (like LineColor, Text, BackStyle, DrawMode).

Data Type

Long (The Object handle)


See also

Editing a Picture

Changing object's attributes

Editing objects

Action property


DrawMode  Property

See Also	Example

Description

The DrawMode property specifies the way in which objects attributes (pen, brush or characters) are combined with the colors already on the display surface. The DrawMode property can accept one of the 16 standard modes of the Windows SetROP2() function.

Usage

[form.]MDraw.DrawMode [= setting%]

Settings

The DrawMode property settings are:

Constant	Value	Calculate

R2_BLACK	1	0	Blackness

R2_NOTMERGEPEN	2	~(PaD)	Not Merge Pen

R2_MASKNOTPEN	3	(~P)oD	Mask Not Pen

R2_NOTCOPYPEN	4	~P	Not Copy Pen

R2_MASKPENNOT	5	Pa(~D)	Mask Pen Not

R2_NOT	6	~D	Invert

R2_XORPEN	7	PxD	Xor Pen

R2_NOTMASKPEN	8	~(PaD)	Not Mask Pen

R2_MASKPEN	9	PaD	Mask Pen

R2_NOTXORPEN	10	~(PxD)	Not Xor Pen

R2_NOP	11	D	Nop

R2_MERGENOTPEN	12	(~P)oD	Merge Not Pen

R2_COPYPEN	13	P	Copy Pen

R2_MERGEPENNOT	14	Po(~D)	Merge Pen Not

R2_MERGEPEN	15	PoD	Merge Pen

R2_WHITE	16	1	Whiteness

Remarks

The Calculate column of the above list contains the expression of the bitwise logical operation to be performed on the pen and the pixels of the destination DC. D means the destination DC, P means the pen, a, x, o, ~ - logical operators and, xor, or, not accordingly. For example, (~P)oD means

Result = (not Pen) or Dest

Note	Objects are displayed according to their stacking order, so all operations are performed from the bottom-most object to the topmost one.

Data Type

Integer (Enumerated)


See also

Layering order of objects

Changing object's attributes


DropMode  Property

See Also	Example

Description

This property determines how the MetaDraw control should handle filenames dropped from the File Manager.

Usage

[form.]MDraw.DropMode [= setting%]

Settings

The DropMode property settings are:

Constant	Value	Description

FDROP_NONE	0	Disable the processing of dropped files.

FDROP_FIRST	1	Process (generate an event for) only the first file in the list.

FDROP_ALL	2	Process (generate an event for) each file in the list.

Remarks

Code should be written in the MetaDraw_DropFile(...) event procedure to handle dropped files. For example, you can load the picture and assign it to the control's picture property.

Sub MetaDraw_DropFile (..., FName As String, ...)

    MDraw.Picture = LoadPicture(FName)

End Sub

Data Type

Integer (Enumerated)


See also

Drag-and-Drop operations

DropFile event


EditFlags  Property

See Also	Example

Description

This property determines which mouse actions are available when the EditMode property is set to ED_EDIT.

Usage

[form.]MDraw.EditFlags [= edit_flg%]

Settings

The EditFlags property can be a combination of the following values:

Constant	Value	Description

EFLG_SELECT	1	Left mouse button click selects an object.

EFLG_SELSHIFT	2	Left mouse button click toggles the selection status of underlying object. That allows the user to make multiple selection of objects.

EFLG_SELGROUP	4	If this bit is set then all objects which located inside the selection rectangle will be marked as "selected".

EFLG_DRAWSCEL	8	Determines how an object will be drawn while it is being dragged. If this bit is set, only the outline of the moving object will be drawn. Otherwise the whole object will be drawn while mouse is dragging.

EFLG_MOVE	16	Object(s) will be moving while the left mouse button is pressed and the mouse is dragging if this bit is set.

EFLG_RESIZE	32	If this bit is set, the user can move an objects marker by mouse (usually to resize an object).

EFLG_OPEN	64	if this bit is set, a double-click of the left mouse button opens underlying object (container).

Remarks

Flags EFLG_SELSHIFT and EFLG_SELGROUP should be set only with EFLG_SELECT flag.

Data Type

Integer


See also:

Editing objects

Selecting objects

EditMode property


Picture edit mode
EditMode  Property

See Also	Example

Description

This property determines the mouse action in the MetaDraw control box.

Usage

[form.]MDraw.EditMode [= setting%]

Settings

The EditMode property settings are:

Constant	Value	Description

ED_VIEW	0	No mouse edit action

ED_LINE	1	Add line mode

ED_RECT	2	Add rectangle mode

ED_ROUND	3	Add rounded rectangle mode

ED_ELLIPSE	4	Add ellipse mode

ED_ARC	5	Add arc mode

ED_PIE	6	Add pie mode

ED_CHORD	7	Add chord mode

ED_POLYLINE	8	Add polyline mode

ED_POLYGON	9	Add polygon mode

ED_TEXT	10	Add text mode

ED_EDIT	11	Select and edit object(s) mode

ED_SELECT	11	Select object(s) mode

ED_IMAGE	12	Add image mode

Remarks

The mouse cursor within the MetaDraw control box has a specific appearance for each edit mode. In the view mode (ED_VIEW value), the mouse is the standard arrow cursor or that cursor specified by MousePointer and MouseCursor properties.

In selection and editing modes (ED_EDIT) the user can select, move or resize objects by the mouse. Any or all of the editing actions can be disabled by EditFlags property.

In view mode (ED_VIEW), no edit action is performed, but an event dependent upon HotSpots, EventMask properties will be triggered.

Data Type

Integer (Enumerated)


See also:

Creating an object using mouse

Hot-Spot abilities

EditFlags property


EventMask  Property

See Also	Example

Description

This property determines which events can be triggered.

Usage

[form.]MDraw.EventMask [= event_mask%]

Settings

The EventMask property can be a combination of the following values:

Constant	Value	Description

EMSK_HITOBJECT	1	Enable HitObject event.

EMSK_ONHOTSPOT	2	Enable OnHotSpot event.

EMSK_SELECT	16	Invoke Change event when object(s) selection was changed.

EMSK_ADD	32	Invoke Change event when new object was added.

EMSK_MOVE	64	Invoke Change event when an object was moved.

EMSK_RESIZE	128	Invoke Change event when a marker was moved.

EMSK_OPEN	256	Invoke Change event when an object or a container was opened.

Remarks

The Change event can be disabled by clearing all following bits: EMSK_SELECT, EMSK_ADD, EMSK_MOVE, EMSK_RESIZE, EMSK_OPEN.

By default, all events are enabled. You can disable any unneeded events for better performance.

Data Type

Integer (The Bitwise mask)


See also

Change event

HitObject event

OnHotSpot event


ExportDC  Property

See Also	Example

Description

Starts the exporting of the picture's objects to a specified Device Context.

Usage

[form.]MDraw.ExportDC = hDC%

Remarks

After the assignment, the MetaDraw control starts drawing objects on specified device context (hDC%). Objects which should be exported are specified in the Current property.

The MetaDraw control always fires the Export event with the State parameter set to EXP_START (before exporting), EXP_PROCESS for each exported object and EXP_FINISH after exporting the last object. You can interrupt exporting in any time by setting the State parameter to EXP_FINISH in the Export event.

The size and position of the exporting picture are determined by the ExportLeft, ExportTop and ExportWidth, ExportHeight properties.

Typically, you are assigning Printer.hDC to this property, which actually prints the objects in the MetaDraw control box.

Data Type

Integer (The Device Context)


See also

Printing with MetaDraw

ExportWidth, ExportHeight properties

ExportLeft, ExportTop properties

Export event


ExportWidth, ExportHeight  Properties

See Also	Example

Description

Determine the width and height of the exporting picture.

Usage

[form.]MDraw.ExportWidth [= width%]

[form.]MDraw.ExportHeight [= height%]

Remarks

These properties are measured in pixels and are dependant upon the physical characteristics of the device context which will be assigned to the ExportDC property.

These properties are used also to determine the dimensions of a bitmap which will be returned by Picture, PictureImage and PictureClip properties when the PictureType property is set to PICTYPE_BITMAP.

If one of these properties had been assigned to zero before exporting, MetaDraw will automatically calculate the appropriate value based on the picture aspect ratio and the non-zero  value assigned to the remaining property.

Data Type

Integer


See also

Printing with MetaDraw

ExportDC property

ExportLeft, ExportTop properties

PictureType property


ExportLeft, ExportTop  Properties

See Also	Example

Description

Determine placement (offsets) of the exporting picture.

Usage

[form.]MDraw.ExportLeft [= x_offset%]

[form.]MDraw.ExportTop [= y_offset%]

Remarks

These properties are measured in pixels and are dependant upon the physical characteristics of the device context which will be assigned to the ExportDC property.

Data Type

Integer


See also

Printing with MetaDraw

ExportDC property

ExportWidth, ExportHeight properties


FillColor  Property

See Also	Example

Description

Determines the color used to fill in objects.

Usage

[form.]MDraw.FillColor [= color_expression&]

Remarks

The FillColor property determines a color for solid fill style or for hatch lines in hatched styles.

Data Type

Long (Color)


See also

Changing object's attributes

BackStyle property

BackColor property


FillPattern  Property

See Also	Example

Description

Specifies the picture (bitmap) to be used as a fill pattern for an object.

Usage

[form.]MDraw.FillPattern [= LoadPicture(...)]

Remarks

Only a Bitmap picture can be assigned to FillPattern property.

Fill patterns are limited to 8x8 pixels.  While any bitmap may be assigned to the FillPattern property, only the 8x8 pixels from its upper-left corner will be used as a brush pattern for the fill object (see CreatePatternBrush() GDI function).

After FillPattern property is assigned, the FillStyle property is set to FS_PATTERN and FillColor property is ignored.

The typical bitmap for the FillPattern should look like a piece of a large regular picture (e.g. the brick in the wall [image]).

Note	If FillStyle is not FS_PATTERN (e.g. was set to FS_SOLID), then FillPattern returns NULL picture.

Data Type

Integer (The Picture handle). The supported picture type is bitmap.


See also

Changing object's attributes

FillStyle property


FillStyle  Property

See Also	Example

Description

Determines the method used to fill object.

Usage

[form.]MDraw.FillStyle [= setting%]

Settings

The FillStyle property settings are:

Constant	Value	View

FS_SOLID	0	solid

FS_TRANSPARENT	1	transparent

FS_HORIZONTAL	2	=====

FS_VERTICAL	3	| | | | |

FS_FDIAGONAL	4	\ \ \ \ \

FS_BDIAGONAL	5	/ / / / /

FS_CROSS	6	+++++

FS_DIAGCROSS	7	xxxxx

FS_PATTERN	8	use bitmap pattern

Remarks

When FillStyle is FS_TRANSPARENT (1), the FillColor property is ignored.

When the FillStyle property is assigning to FS_PATTERN (8), a bitmap pattern from the global object's attributes is used for FillPattern property.  The FillStyle property is set to FS_PATTERN automatically when the FillPattern property changes.

Data Type

Integer (Enumerated)


See also

Changing object's attributes

FillColor property

FillPattern property


FontOrient  Property

See Also	Example

Description

Specifies the angle, in degrees, between the base line of the characters of the text object and the x-axis.

Usage

[form.]MDraw.FontOrient [= angle#]

Remarks

The angle is measured counterclockwise from the x-axis. The user can assign negative values to this property. In this case, the angle is measured in a clockwise direction.

The FontOrient property applies only to TrueType fonts. If the font specified by the FontName property is not TrueType then this property is ignored and text is painted horizontally.

This property applies only to text objects.

Data Type

Single


See also

Changing object's attributes

FontStyle property


FontSize  Property

Description

Determines the font size for a text object.

Usage

[form.]MDraw.FontSize [= font_size#]

Remarks

This property is measured in points (1/72 inch) if the value supplied is positive. If the value is negative, then it's absolute value is used to specify the font size in picture logical coordinates.

This property applies only to text objects.

For more information, see the description of the FontSize property in the Microsoft Visual Basic Language Reference.

Data Type

Single


FontStyle  Property

See Also	Example

Description

This property determines how the text font will be changed after changing text object boundaries.

Usage

[form.]MDraw.FontStyle [= settings%]

Settings

The FontStyle property settings are:

Constant	Value	Description

FSTL_FIXED	0	The text font will always have a fixed size independent of the size of the container where it is placed.

FSTL_PROPOR	1	Font size will be calculated according to the text object boundaries and font aspect ratio.

FSTL_SCALABLE	2	Height and width of font is adjusted according to the text object boundaries in order to fit the text string in these boundaries.

Remarks

Text object boundaries can be changed by the mouse (by dragging markers) in the edit mode or after changing boundaries of the parent container.

Size of the font can be also changed by assigning the FontSize property. It is true only for FSTL_FIXED and FSTL_PROPOR styles.

Data Type

Integer (Enumerated)


See also

Changing object's attributes

FontOrient property


Align to grid
GridAlign  Property

See Also	Example

Description

This property determines whether or not to align object coordinates to the grid while it is editing.

Usage

[form.]MDraw.GridAlign [= {True|False}]

Remarks

The grid allows the user to align and place objects precisely with the mouse.

When GridAlign is True any objects or containers that you create, move or resize will snap to the nearest grid marker.

Data Type

Integer (Boolean)


See also

Creating an object using the mouse

Editing objects using the mouse

Grid size properties


Grid width and height
GridWidth, GridHeight  Properties

See Also	Example

Description

These properties determine the distance between grid markers in picture logical units.

Usage

[form.]MDraw.GridWidth [= x_size%]

[form.]MDraw.GridHeight [= y_size%]

Remarks

GridWidth and GridHeight properties determine the distance between two neighboring grid markers. They can be assigned values from 1 to PicWidth (x) or PicHeight (y).

Data Type

Integer


See also

Editing objects using the mouse

GridAlign property


Show grid
GridShow  Property

See Also	Example

Description

This property determines whether or not to show grid markers.

Usage

[form.]MDraw.GridShow [= {True|False}]

Remarks

The grid is a set of points, one black screen pixel each. The GridWidth and GridHeight properties specify the distance between these points.

The grid is shown only if the distance between two neighboring markers are greater than 5 screen pixels on the x-axis and y-axis. Along with GridWidth and GridHeight, the screen distance between grid points depends upon the current scaling mode (PicXSize/PicYSize and PicWidth/PicHeight properties).

Data Type

Integer (Boolean)


See also

GridAlign property

Grid size properties


hDC  Property

See Also	Example

Description

This property specifies a handle provided by the Windows Environment to the device context of a MetaDraw picture box which you can use as a parameter to Windows GDI function calls to paint (add) a new object into the picture.

Usage

hDC% = [form.]MDraw.hDC

res = SomeGDICall (hDC%, ...)

[form.]MDraw.hDC = {True|False}

Remarks

When the user reads this property in first time the MetaDraw control creates a DC of memory metafile and returns its handle as a result. The next time you read this property it will return a handle of the previously created metafile DC. You can destroy previously created DC assigning False to this property.

When metafile DC is created first time, the origins and extents of the window associated with this device context are set to (PicLeft, PicTop) and (PicWidth, PicHeight) respectively. The mapping mode of DC is set to MM_ANISOTROPIC. In other words, the MetaDraw control adds the following metafile records to the metafile DC after it has been created:

SetMapMode(hDC, MM_ANISOTROPIC)

SetWindowOrg(hDC, PicLeft, PicTop)

SetWindowExt(hDC, PicWidth, PicHeight)

Besides the MetaDraw control sets pen, brush and font according to currently global attributes.

Assigning this property to True finishes drawing and adds all the new objects to the open container. You can abort the drawing action by assigning False to this property.

Note	This property gives you the unique ability to draw over the pictures of any of VB-supported types - bitmaps, metafiles. However, to use this possibility, you should understand how Windows GDI functions work. Remember that any technique involving the lower-level Windows APIs is more complex and less safe than the pure-VB programming!

Data Type

Integer (The Device Context handle)


See also

Creating an object using the AddItem method

ExportDC property


HotSpots  Property

See Also	Example

Description

This property determines whether or not to enable the hotspot abilities of the MetaDraw control.

Usage

[form.]MDraw.HotSpots [= {True|False}]

Settings

The HotSpots property settings are:

Setting	Description

True	Enable hotspots abilities.

False	Disable hotspots abilities.

Remarks

The hotspot abilities are available only in the MetaDraw control view mode (the EditMode property is ED_VIEW).

If the HotSpots property is True, then the mouse pointer will change its shape to the HAND cursor when it is moving over "hotspot" objects. Also, the OnHotSpot event will occur when mouse pointer enters, leaves or drags over "hotspot" objects.

Data Type

Integer (Boolean)


See also

Using Hot-Spot abilities

OnHotSpot event

ObjHotSpot property


hPal  Property

Description

Determines a logical palette that is used for displaying the current picture.

Usage

[form.]MDraw.hPal [= hPal%]

Remarks

MetaDraw never changes or deletes the assigned palette and copies it to its own identical palette. The user is responsible for deleting the original (prototype) palette, but should not delete or modify its working copy created by MetaDraw.

Data Type

Integer (The Palette handle)


LineColor  Property

See Also	Example

Description

Determines the color of a line or an objects border.

Usage

[form.]MDraw.LineColor [= color_expression&]

Data Type

Long (Color)


See also

Changing objects attributes

LineStyle property

LineWidth property


LineStyle  Property

See Also	Example

Description

Determines the line style for line and polyline objects or the border style for other objects.

Usage

[form.]MDraw.LineStyle [= setting%]

Settings

The LineStyle property settings are:

Constant	Value	View

PS_SOLID	0	_____

PS_DASH	1	_ _ _ _

PS_DOT	2	. . . . . .

PS_DASHDOT	3	_ . _ . _

PS_DASHDOTDOT	4	_ . . _ . . _

PS_NULL	5	Ignore border

PS_INSIDEFRAME	6	Inside Solid. The outer edge of the border is the outer edge of the object. Like PS_SOLID for line, polyline and polygon objects.

Remarks

If LineStyle is PS_INSIDEFRAME, the border is drawn inside the objects boundaries (this value is valid only for shape objects: rectangles, ellipse, sectors). If LineStyle is PS_SOLID, the border is centered around the objects boundaries.

Note	Non-solid line styles are ignored and the lines are drawn SOLID if the visible line width is greater then one pixel. To guarantee that the line is non-solid, specify LineWidth = 0, which means a  pixel width of 1 on a display of any resolution.

Data Type

Integer (Enumerated)


See also:

Changing objects attributes

LineColor property

LineWidth property


LineWidth  Property

See Also	Example

Description

Determines the width of the line or the object border width.

Usage

[form.]MDraw.LineWidth [= width#]

Remarks

The LineWidth property is measured in points (1/72 inch). You can specify the line width in logical picture units if you assign this property a negative value (the absolute value is taken as the width).

To get lines of minimal size on the given device (one pixel), use LineWidth = 0. This property is always 0 if LineStyle property is not PS_SOLID or PS_INSIDEFRAME.

Data Type

Integer


See also:

Changing objects attributes

LineColor property

LineStyle property


MarkerSize  Property

See Also	Example

Description

This property determines the size of selection markers in twips.

Usage

[form.]MDraw.MarkerSize [= mrk_size%]

Remarks

If the MarkerSize property is set to zero, the markers would not be drawn, and mouse functions that use markers (like resize object) will not available.

Data Type

Integer


See also:

Editing objects


MouseCursor  Property

See Also	Example

Description

Defines the mouse cursor shape when MousePointer property is MPTR_USER.

Usage

[form.]MDraw.MouseCursor = LoadPicture("...")

Remarks

When you assign a picture to the MouseCursor property, the cursor is produced from this picture. Use this property to provide customized cursors.

Remember that the Visual Basic does not allow you to load actual cursors (defined in .CUR files) with the LoadPicture() function. When you load an icon from an .ICO-file and then use it as a cursor, the icon image is converted to monochrome and the hot-spot is set to its default position at the middle of the image.

Data Type

Picture


See also:

MousePointer property


MousePointer  Property

See Also	Example

Description

Determines the type of mouse pointer which will be used inside the MetaDraw control.

Usage

[form.]MDraw.MousePointer [= settings%]

Settings

The MousePointer property setting are:

Constant	Value	Description

MPTR_DEFAULT	0	(default) Shape determined by the edit mode.

MPTR_ARROW	1

MPTR_CROSS	2

MPTR_HBEAM	3

MPTR_ICON	4

MPTR_SIZE	5

MPTR_SIZENESW	6

MPTR_SIZENS	7

MPTR_SIZENWSE	8

MPTR_SIZEWE	9

MPTR_UPARROW	10

MPTR_HOURGLASS	11

MPTR_NODROP	12

MPTR_USER	15	The shape of the mouse pointer is determined by MouseCursor property.

MPTR_MOVE	16

MPTR_SCROLL	17

MPTR_HOTSPOT	18

MPTR_DRAWPEN	19

Values above 19 (20+ED_xxxx) determine the cursor shape for the edit modes (e.g. value 29 = 20+ED_POLYGON determines the cursor  [image]).

Remarks

The MousePointer property controls the shape of the mouse pointer. This property is useful when you want to indicate changes in functionality as the mouse pointer passes over the control.

Data Type

Integer (Enumerated)


See also:

MouseCursor property


Logical object coordinates
ObjLeft, ObjTop, ObjRight, ObjBottom  Properties

See Also	Example

Description

These properties determine the logical coordinates of the boundaries of an object or group of objects.

Usage

left% = [form.]MDraw.ObjLeft

top% = [form.]MDraw.ObjTop

right% = [form.]MDraw.ObjRight

bottom% = [form.]MDraw.ObjBottom

Remarks

These properties determine the bounding rectangle, in logical picture coordinates, for the object specified by the Current property. If Current specifies a group of objects (selected objects), the bounding rectangle is the smallest rectangle that contains all specified objects.

Use the MD_SetBounds() function or the MetaDraw control mouse editing tools to change object boundaries. Also, the user can receive the objects' bounding rectangle using MD_GetBounds() function.

Data Type

Integer


See also:

Picture's coordinates

Current property

MD_GetBounds() API function


ObjCount  Property

See Also	Example

Description

This property returns the number of objects which are specified by index (object_type%).

Usage

number_objects = [form.]MDraw.ObjCount(object_type%)

Settings

The parameter can be one of the following values:

Constant	Value	Description

OBJ_CONTAINER	1	Returns the number of objects within the open container.

OBJ_SELECTED	2	Returns the number of selected objects.

OBJ_CURRENT	4	Use Current property for specified container for which Count function is applied.

OBJ_CONT_MAIN	5	Returns total number of objects in the picture.

OBJ_IMAGE	6	Returns total number of objects in the picture that is kept in the PictureImage property. If no picture defined in the PictureImage property, zero is returned.

Remarks

Except for the OBJ_CONTAINER and OBJ_SELECTED values, the ObjCount property returns a total number of objects inside the picture (OBJ_CONT_MAIN), inside the container specified by Current property (OBJ_CURRENT) or inside the image (OBJ_IMAGE), including all containers and objects inside it. For the OBJ_CONTAINER and OBJ_SELECTED values, this property returns the number of objects that are in the current container (container is a single object).

Data Type

Integer


See also:

Current property

ObjNumber property


ObjHitable  Property

See Also	Example

Description

This property is used to test or toggle the objects "hitable" status.

Usage

[form.]MDraw.ObjHitable [= {True|False}]

Remarks

If an object has "hitable" flag (ObjHitable is True for it) , then HitObject event will be triggered in response to mouse click on this object.

Data Type

Integer (Boolean)


See also:

Changing objects attributes

Use Hot-Spot abilities

Current property

HitObject event


ObjHotSpot  Property

See Also	Example

Description

This property is used to test or toggle objects "hotspot" status.

Usage

[form.]MDraw.ObjHotSpot [= {True|False}]

Remarks

If ObjHotSpot is True the object is marked as a "hotspot". In viewing mode (with HotSpots property is True) the mouse pointer will change its shape and the OnHotSpot event will be triggered as the mouse moves over the object.

Data Type

Integer (Boolean)


See also:

Changing objects attributes

Use Hot-Spot abilities

HotSpots property

OnHotSpot event


ObjMove  Property

See Also	Example

Description

This is an action property which changes the current object in the pictures objects list.

Usage

[form.]MDraw.ObjMove [= settings%]

Settings

The ObjMove property settings are:

Constant	Value	Description

MOVE_NEXT	0	Move pointer in the Current property to the next object in the list.

MOVE_PREV	1	Move pointer Current to the previous object.

MOVE_FIRST	2	Move pointer Current to the first object in the list of objects.

MOVE_LAST	3	Move pointer Current to the last object.

MOVE_PARENT	4	Move pointer Current to the parent container.

MOVE_CHILD_FIRST	5	Move pointer to first child in container's objects list. Current property must contain handle of a container.

MOVE_CHILD_LAST	6	Move pointer to the last child in container's objects list. Current property must contain handle of a container.

MOVE_SEL_NEXT	7	Move pointer to the next selected object.

MOVE_SEL_PREV	8	Move pointer to the previous selected object.

MOVE_SEL_FIRST	10	Move pointer to first selected object.

MOVE_SEL_LAST	11	Move pointer to last selected object.

MOVE_OPENED	12	Set Current pointer to the handle of the currently open object (or container).

MOVE_CONT_MAIN	13	Set Current pointer to the handle of the main container.

MOVE_CONT_FIRST	14	Set Current pointer to the handle of first object in the open container objects list.

MOVE_CONT_LAST	15	Set Current pointer to the handle of last object in the open container object list.

Remarks

If no more specified objects are found, Current is OBJ_NULL. For example, if Current contains the handle of the first selected object and the Current property will be set to  OBJ_NULL after ObjMove is assigned to MOVE_SEL_PREV.

Note	The Current property must have a valid object handle before assigning values from MOVE_NEXT (0) till MOVE_SEL_PREV (8). For another values the Current property can be undefined.

Data Type

Integer (Enumerated)


See also:

Changing objects attributes

Editing objects

Current property


ObjNumber  Property

See Also	Example

Description

This property is used to convert between an objects order number and its handle.

Usage

[form.]MDrdaw.ObjNumber [= object_number&]

Remarks

This property returns the order number within the container for the object whose handle is specified in the Current property. The value in the Current property is not changed.

When set, MetaDraw will reset the Current property to the handle of the corresponding object inside the container whose handle is specified in the Current property . If the specified value is less than a number of objects in the container, then the Current property will be set to OBJ_NULL.

Data Type

Long


See also:

Current property

ObjCount property


ObjOpened  Property

See Also	Example

Description

This property is used to test or toggle an objects "open" status.

Usage

[form.]MDraw.ObjOpened [= {True|False}]

Remarks

This property returns the opened status of an object whose handle is specified in the Current property.

Setting to True opens the object pointed by the Current property. If the handle of a container was specified in the Current property, then this container becomes to be the current open container. When the single object is specified in the Current property, it receives "open" status and the user can change additional parameters of the object (polyline points, rounded corners, text characters an so on) using the mouse (when the EditMode property is ED_EDIT). Only one object can have an "open" status at a time.

Setting to False closes the object and opens its parent.

Note	The Current property must contain a real object handle (not a reserved handle). Only some objects can be opened: rounded rectangle, arc, sector, chord, polyline, polygon, text and container.

Data Type

Integer (Boolean)


See also:

Changing objects attributes

Open container

Current property


ObjSelected  Property

See Also	Example

Description

Using for testing or changing the object selection status.

Usage

[form.]MDraw.ObjSelected [= {True|False}]

Remarks

Using this property you can change or test the selection status for the object referenced by the Current property. If the Current property contains OBJ_CONTAINER reserved handle, then all objects inside the current container will be selected (True) or dropped from selection (False).

Only objects which are in the open container object list can be marked as selected. The mouse can also be used to change object selection status (in ED_EDIT edit mode).

Data Type

Integer (Boolean)


See also:

Changing objects attributes

Selecting objects


ObjTag  Property

See Also	Example

Description

Specifies any extra data to be associated with a given object. You can use this property to identify objects, or to hold a string for use in a HyperGraphic application when the the user clicks, etc.

Usage

[form.]MDraw.ObjTag [= tag_string$]

Remarks

By default the ObjTag property is set to an empty string ("") upon creation of an object.

Data Type

String


See also:

Changing objects attributes

Using Hot-Spot abilities

Current property


ObjType  Property

See Also	Example

Description

Returns type of the object or group of the objects.

Usage

object_type = [form.]MDraw.ObjType

Settings

The ObjType property settings are:

Constant	Value	Description

OT_CONTAINER	0	Container (group of the objects)

OT_LINE	1	Line

OT_RECTANGLE	2	Rectangle

OT_ROUNDRECT	3	Rounded rectangle

OT_ELLIPSE	4	Ellipse (circle)

OT_ARC	5	Arc

OT_PIE	6	Pie (sector)

OT_CHORD	7	Chord

OT_POLYLINE	8	Polyline

OT_POLYGON	9	Polygon

OT_TEXT	10	Text

OT_BITMAP	11	Bitmap

Remarks

This property returns type of object(s) that is specified in the Current property. If Current specifies more then one object (a group of selected objects) and these objects are not the same type, OBJ_NULL will be returned.

Data Type

Integer


See also:

Current property


ObjVisible  Property

See Also	Example

Description

This property is used to test or toggle the objects visible status.

Usage

[form.]MDraw.ObjVisible [= {True|False}]

Remarks

When this flag is False the object will not be shown, but all events will occur.

This flag is used only in view picture mode (EditMode property is ED_VIEW). In other editing modes all objects are always visible.

Data Type

Integer (Boolean)


See also:

Changing objects attributes

Using Hot-Spot abilities

Current property


OpenDraw Property

See Also	Example

Description

This property determines which part of the picture will be painted. It can be either the entire picture or only the open container.

Usage

[form.]MDraw.OpenDraw [= settings%]

Settings

The OpenDraw property settings are:

Constant	Value	Description

OPDR_FULL	0	Paint the whole picture.

OPDR_CONTAINER	1	Paint only the open container.

OPDR_HATCHED	2	Paint objects which lie outside the open container as hatched outlines.

Remarks

When the container is opened (by mouse double-click or by assigning True to the ObjOpened property) the picture will be automatically repainted.

Data Type

Integer (Enumerated)


See also:

Repaint property


Original picture size
OrigWidth, OrigHeight  Properties

See Also	Example

Description

The OrigWidth and OrigHeight properties are the original height and width of the picture in units specified by the parent control scaling mode (by default is in twips).

Usage

Width = [form].MDraw.OrigWidth

Height = [form].MDraw.OrigHeight

Remarks

Every picture created or loaded into a MetaDraw control has a certain height and width as its intrinsic attributes. They were defined when the picture was first created and cannot be changed afterwards. The original size is calculated depending upon the picture type. For a bitmap or an icon, it is produced from the bitmaps pixel dimensions (or icons standard dimensions), using the current display resolution. For a metafile, the original size is stored in a header which VB provides for every metafile loaded.

The OrigWidth/OrigHeight properties can be changed using VB code only when there is no picture loaded in the control. Set them to determine the actual dimensions of the picture being created, then create it by assigning to the Picture property. Once a picture is created or loaded, the MetaDraw sets these properties automatically, to reflect the original picture size.

When a picture is loaded, the typical use of OrigWidth/OrigHeight properties is to determine the visible size of a zoomed picture. For example, the following code displays the picture 200% enlarged relative to its original size:

MDraw.PicXSize = MDraw.OrigWidth * 2

MDraw.PicYSize = MDraw.OrigHeight * 2

The user can use the property AutoScale to display picture with its original sizes.

Data Type

Single


See Also:

Picture's coordinates

AutoScale properties

PicXSize, PicYSize properties


Background and border picture color
PicBackColor, PicBorderColor  Properties

See Also	Example

Description

The PicBackColor property specifies the color to be used as a background inside the picture rectangle.

The PicBorderColor property specifies the color to be used as a background outside the picture bounds or when no picture is present.

Usage

[form].MDraw.PicBackColor [= color_expression&]

[form].MDraw.PicBorderColor [= color_expression&]

Remarks

PicBackColor and PicBorderColor are used as shown on the following picture:

When no picture is loaded in the MetaDraw control its the client window will be filled with color determined by the PicBorderColor property.

PicBackColor is also used as transparent color in the conversion of the picture to ICON.

Data Type

Long (Color)


See Also

Displaying and Scrolling the picture


Logical coordinates of the picture
PicLeft, PicTop, PicWidth, PicHeight  Properties

See Also	Example

Description

These properties specify the origin and extent of the given picture in logical units.

Usage

[form].MDraw.PicLeft [= some_X%]

[form].MDraw.PicTop [= some_Y%]

[form].MDraw.PicWidth [= some_W%]

[form].MDraw.PicHeight [= some_H%]

Remarks

These properties can be changed only while there is no picture assigned to the control, but PicWidth or PicHeight can be assigned to zero. In this case, the current picture will be destroyed and the picture will no longer be loaded in the MetaDraw control box.

When you assign a new picture to the MetaDraw control, the scaling properties are automatically changed to reflect the logical units for the new picture:

*	If the picture is a bitmap or an icon, the PicLeft and PicTop properties become zero, and the PicWidth and PicHeight get their values from the actual bitmap dimensions (in pixels).

*	If the picture is a metafile, the MetaDRAW searches through the metafile for the SetWindowOrg() and SetWindowExt() records and uses their parameters to set logical units.

*	If there are no SetWindowOrg()/SetWindowExt() records near the beginning of the metafile, then the PicLeft and PicTop properties are set to lowest values used in the metafiles records, and the PicWidth/PicHeight are set to the difference between highest and lowest values.

*	The original size (OrigWidth/OrigHeight properties) is calculated differently, depending on the picture type. For a bitmap or an icon, it is produced from the bitmaps pixel dimensions (or icons standard dimensions), using the current display resolution. For a metafile, the original size is stored in a header which VB provides for every metafile loaded.

*	Offsets of the picture visible rectangle (PicXOfs, PicYOfs properties) are assigned a value of zero (picture will be displayed from left-top corner of the MetaDraw control box). Size of the visible picture (PicXSize, PicYSize properties) is assigned the original picture size.

Note	These properties are integers, not scaleable Single (floating point) values as in other coordinate/size properties. They dont depend upon the parent controls scaling mode. They determine only resolution of the picture that is loaded in the MetaDraw control box.

Data Type

Integer


See Also

Picture's coordinates

Picture position and visible size

Creating a new picture


Picture  Property

See Also	Example

Description

This property is used to export or import a picture to/from the MetaDraw control.

Usage

[form.]MDraw.Picture [= LoadPicture("...")]

Remarks

When a new picture is assigned to the control, the current picture is destroyed and new picture converted into internal format.

*	Metafile. All metafile records are converted to proper MetaDraw graphical objects.

*	Bitmap and icon. Create picture with one bitmap object.

*	If an empty picture is assigned to this property (using LoadPicture("")), an empty picture will be created with current settings for PicLeft, PicTop, PicWidth, PicHeight, OrigWidth, OrigHeight properties.

After the picture is created, the PicXOfs, PicYOfs properties are set to zero and PicXSize, PicYSize are set to OrigWidth, OrigHeight accordingly (or to PicWidth/PicHeight if no original size is specified).

When this property is accessed, the current picture is copied into a new VB-compatible picture of a type specified in PictureType property.

Data Type

Integer (The Picture Handle)


See also:

Picture's coordinates

Displaying and scrolling picture

PictureImage property

PictureClip property

PictureType property


PictureChanged  Property

See Also	Example

Description

Determines were or not any changes in the picture.

Usage

[form.]MDraw.PictureChanged [= {True|False}]

Remarks

The MetaDraw control sets the PictureChanged property to True when any changes in the currently loaded picture were made (move objects, change attributies and so on).

Note	The MetaDraw control sets this property to False only when the Picture property have been assigned or read. In other case, the user should drop this flag itself.

Data Type

Integer (Boolean)


See also:

Creating a new picture

Editing a picture


Import and export picture property
PictureClip  Property

See Also	Example

Description

Using this property you can merge any picture to current picture or retrieve any part of it.

Usage

[form.]MDraw.PictureClip [= LoadPicture("...")]

Remarks

The picture being assigned is converted to a graphical object (container will be created if there are more than one metafile records) and the resulting object is inserted into the current picture using its original size and offset. If new object does not fit into the picture (larger then the current picture) it is stretched.

When this property is read, part of the current picture specified by the Current property will be converted to a VB picture of the type specified by the PictureType property.

Data Type

Integer (The Picture Handle)


See also:

Picture's coordinates

Picture property

PictureType property


PictureImage  Property

See Also	Example

Description

Determines the picture which will be used in add image operations.

Usage

[form.]MDraw.PictureImage [= LoadPicture("...")]

Remarks

The picture which is saved in this property will be used as a new element in the adding image edit mode (EditMode property is ED_IMAGE) or when the second parameter in the AddItem method is OT_IMAGE.

Also, this property can be used for saving temporary pictures. There is an easy way to exchange pictures between Picture and PictureImage properties using the Action property (see ACT_IMAGExxxx constants).

Data Type

Integer (The Picture Handle)


See also:

Picture's coordinates

Creating a new object

Action property

Picture property

PictureClip property


Type of the picture for export
PictureType  Property

See Also	Example

Description

Determines the type of picture to export.

Usage

[form.]MDraw.PictureType [= setting%]

Settings

The PictureType property settings are:

Constant	Value	Description

PICTYPE_NONE	0	-

PICTYPE_BITMAP	1	Export picture as bitmap.

PICTYPE_METAFILE	2	Export picture as extended metafile.

PICTYPE_ICON	3	Export picture as icon.

PICTYPE_PLAINWMF	4	Export picture as plain Windows metafile (without comment records).

Remarks

This property is in effect only when the Picture, PictureClip or PictureImage properties are read.

If the PictureType property is PICTYPE_BITMAP (1) the ExportWidth and ExportHeight properties determine size of the exported bitmap.

Data Type

Integer (Enumerated)


See also:

Picture property

PictureClip property

PictureImage property


PicXOfs, PicYOfs  Properties

See Also	Example

Description

These properties determine the offset of the upper-left corner of the visible area from the upper-left corner of the picture. The offset is measured in units specified by the parent controls ScaleMode, ScaleLeft, ... properties (which by default are twips).

Usage

[form.]MDraw.PicXOfs [= X_offset]

[form.]MDraw.PicYOfs [= Y_offset]

Remarks

Changing these offsets has the effect of scrolling the picture in the box. These properties are also changed when the picture is manually scrolled by mouse action.

If the ScrollCheck property is True and new values are assigned to PicXOfs, PicYOfs, these values are checked and adjusted as needed to keep the picture inside the box.

Data Type

Long


See Also

Picture's coordinates

Picture position and size

Displaying and Scrolling picture

AutoScale property

ScrollCheck property


PicXSize, PicYSize  Properties

See Also	Example

Description

The PicXSize and PicYSize properties are the visible height and width of the picture, in units specified by the parent controls ScaleMode, ScaleLeft, ... properties (which by default are in twips).

Usage

[form.]MDraw.PicXSize [= new_picture_width]

[form.]MDraw.PicYSize [= new_picture_height]

Remarks

Changing the PicXSize and PicYSize properties affects the visible size of the picture displayed in the MetaDraw box. If the value of PicXSize (or PicYSize) is greater than the original picture size, then the picture looks stretched horizontally (or vertically).

For example, to show the middle of the visible rectangle 1.5 times zoomed, you can write code like this (PicXOfs and PicYOfs are also changed to fix the given point at the center of the box):

MDraw.PicXSize = MDraw.PicXSize * 1.5

MDraw.PicYSize = MDraw.PicYSize * 1.5

MDraw.PicXOfs = MDraw.PicXOfs * 1.5

MDraw.PicYOfs = MDraw.PicYOfs * 1.5

PicXSize or PicYSize property can be assigned to 0. In this case, the picture will not be displayed. All background of the MetaDraw control box will be filled with color that is specified in the PicBorderColor property.

Note	The PicXSize/PicYSize properties have nothing in common with the logical picture units which are specified by the PicLeft, PicTop, PicWidth, PicHeight properties.

Data Type

Long


See Also:

Picture's coordinates

Picture position and size

Displaying and Scrolling picture

AutoScale property


Redraw  Property

See Also	Example

Description

This property determines whether or not to repaint picture automatically after any changes.

Usage

[form.]MDraw.Redraw [= {True|False}]

Remarks

If Redraw property is True, picture will be updated after any change (scrolling, resizing, change of an object's attributes, etc.).

If Redraw is False, the picture will not be repainted after changes, but the user can repaint it using the Refresh method. Moreover, the picture will be repainted (if it had been changed and Redraw property was False) after assigning the Redraw property to True.

Data Type

Integer (Boolean)


See also:

Refresh method


Repaint  Property

See Also	Example

Description

Determines the painting method for the picture.

Usage

[form.]MDraw.Repaint [= settings%]

Settings

The Repaint property settings are:

Constant	Value	Description

PAINT_NORMAL	0	The MetaDraw control will paint the picture as a metafile (redraw object by object).

PAINT_BUFFERED	1	The MetaDraw control will use an offscreen bitmap for a fast-looking repaint.

Remarks

If Repaint is PAINT_NORMAL then the picture will be drawn to screen immediately.

If Repaint is PAINT_BUFFERED the picture object will first be drawn on a temporary bitmap in memory, after which the resulting bitmap will be drawn on screen.

Data Type

Integer (Enumerated)


See also:

Redraw property


ScrollBars  Property

See Also	Example

Description

This property determines whether or not to show the scrollbars on the right and bottom sides of the MetaDraw control. Scroll bars allow the user to scroll the picture by clicking the mouse on these bars.

Usage

[form.]MDraw.ScrollBars [= setting%]

Settings

The ScrollBars property settings are:

Constant	Value	Description

BAR_NONE	0	No scrollbars are shown.

BAR_AUTO	1	(Default) Each of the two scrollbars is automatically enabled if scrolling is possible in the corresponding direction. That is, the horizontal scrollbar is enabled when picture width PicXSize is greater than width of the client area of the control and the vertical bar is enabled when PicYSize is greater than height of the client area. Note that the client rectangle (where you can see the picture) will change its size depending upon which scrollbars are visible.

BAR_ALWAYS	2	Both Horizontal and Vertical scrollbars are always visible. However, you still cant scroll if the picture is smaller than the box. The advantage is that the MetaDraw boxs client area remains the same for any picture loaded.

Remarks

Whether the scroll bars are enabled or not, the user can scroll (drag) the picture through use of the mouse or keyboard.

Note	The scroll bars do not function in design mode.

Data Type

Integer (enumerated)


See also:

Picture's coordinates

Picture position and size

Displaying and scrolling the picture


ScrollCheck  Property

See Also	Example

Description

This property determines whether or not to check visible picture bounds after the picture is scrolled or resized.

Usage

[form.]MDraw.ScrollCheck [= {True|False}]

Setting

The ScrollCheck property settings are:

Setting	Description

True	Enables automatic checking for the visible picture rectangle after the picture is scrolled or resized.

False	Disable any checking after changing PicXOfs, PicYOfs, PicXSize, PicYSize properties.

Remarks

If ScrollCheck is True, and you assign new values to PicXOfs, PicYOfs or PicXSize, PicYSize then these values are checked and adjusted as needed to keep the picture inside the box: negative values are changed to zero, large positive values are adjusted so that the right edge of the picture is at the right edge of the box. If the picture fully fits in the box vertically or horizontally (cant be scrolled in this direction), then the corresponding PicXOfs/PicYOfs property is always zero and the assigning new values have not any effects.

If ScrollCheck property is False, no checks are made. The picture can be placed anywhere in the window or beyond it.

Data Type

Integer (Boolean)


See also:

Displaying and scrolling the picture

ScrollBars property


ScrollKeyboard  Property

See Also	Example

Description

This property determines whether or not to allow the user to scroll the picture in the control using the keyboard.

Usage

[form.]MDraw.ScrollKeyboard [= {True|False}]

Settings

The ScrollKeyboard property settings are:

Setting	Description

True (default)	Allows the MetaDraw control to scroll the picture by the keyboard.

False	Keyboard scrolling is disabled.

Remarks

When ScrollKeyboard is True and the MetaDraw control has focus, MetaDraw interprets several cursor keys to scroll the picture vertically and horizontally. All keyboard messages for these keys are consumed inside the MetaDraw and do not cause any VB events.

When ScrollKeyboard is False, the default keyboard processing is disabled and the programmer can process any of the cursor keys in the KeyDown/KeyUp and KeyPress events. The following table shows the standard interpretation of the control keys.

Virtual key code	Scrolls	With [Ctrl] pressed

VK_LEFT	1 pixel left	Window width left

VK_RIGHT	1 pixel right	Window width right

VK_UP	1 pixel up	---

VK_DOWN	1 pixel down	---

VK_PRIOR (PgUp)	'Height' pixels up	To the top of picture

VK_NEXT (PgDn)	'Height' pixels down	To the bottom of picture

VK_HOME	To the left edge	---

VK_END	To the right edge	---

Data Type

Integer (Boolean)


See also:

Displaying and scrolling the picture

ScrollBars property

ScrollCheck property

ScrollMouse property


ScrollMouse  Property

See Also	Example

Description

This property determines whether or not to allow the user to drag (scroll) the picture using the mouse.

Usage

[form.]MDraw.ScrollMouse [= {True|False}]

Settings

The ScrollMouse property settings are:

Setting	Description

True	Scroll picture while the right mouse button is pressed and mouse is dragging.

False	Mouse scrolling is disabled.

Remarks

Even if the mouse scrolling and the scroll bars are all disabled, the picture can still be scrolled at runtime by changing the PicXOfs and PicYOfs properties from the code.

Data Type

Integer (Boolean)


See also:

Displaying and scrolling the picture

ScrollBars property

ScrollCheck property

ScrollKeyboard property


Picture property
ShowInvisible  Property

See Also	Example

Description

This property determines whether or not to paint objects whose ObjVisible attribute is False.

Usage

[form.]MDraw.ShowInvisible [= {True|False}]

Settings

The ShowInvisible property settings are:

Setting	Description

True	All objects will be drawn.

False	Only objects which have ObjVisible property set to True will be drawn.

Remarks

If the container does not have set Visible flag it will not be displayed, even if objects inside it have Visible flag.

Data Type

Integer (Boolean)


See also:

Changing objects attributes

Using Hot-Spot abilities


Text  Property

See Also	Example

Description

This property determines the text string for the text object(s) whose handle is specified in the Current property.

Usage

[form.]MDraw.Text [= string$]

Remarks

The text string can be contain from 1 to 32767 characters. The text string can not contain NULL characters (Chr(0)).

After assigning a new string to the text object its boundaries will be recalculated according to the FontSize, TextHAlign, TextVAlign properties and previous boundaries.

If you are assigning the empty string to the text object then it will be deleted.

This property is available only for text objects (ObjType property is OT_TEXT).

Data Type

String


See also:

Changing objects attributes

ObjType property


TextColor  Property

See Also	Example

Description

Specifies the color of the characters for the text object.

Usage

[form.]MDraw.TextColor [= color_expression&]

Remarks

This property is available only for text objects (ObjType property is OT_TEXT).

Data Type

Long (Color)


See also:

Changing objects attributes

BackColor property

BackStyle property

ObjType property


TextHAlign  Property

See Also	Example

Description

This property determines how text will be aligned in horizontal direction.

Usage

[form.]MDraw.TextHAlign [= settings%]

Settings

The TextHAlign property settings are:

Constant	Value	View

TXT_LEFT	0	Text will be aligned to the left side of the bounding rectangle.

TXT_CENTER	1	Text will be drawn in the middle of the bounding rectangle.

TXT_RIGHT	2	Text will be aligned to the right side of the bounding rectangle.

Remarks

This property is helpful when a text object is inserted inside a container and the user changes the container boundaries.

This property is available only for text objects (ObjType property is OT_TEXT).

Data Type

Integer (Enumerated)


See also:

Changing objects attributes

Text property

TextVAlign property


TextVAlign  Property

 See Also	Example

Description

This property determines how text will be aligned in vertical direction.

Usage

[form.]MDraw.TextVAlign [= settings%]

Settings

The TextVAlign property settings are:

Constant	Value	View

TXT_TOP	0	Text will be aligned to the top side of the bounding rectangle.

TXT_CENTER	1	Text will be drawn in the middle of the bounding rectangle.

TXT_BOTTOM	2	Text will be aligned to the bottom side of the bounding rectangle.

Remarks

This property is helpful when a text object is inserted inside a container and the user changes the container boundaries.

This property is available only for text objects (ObjType property is OT_TEXT).

Data Type

Integer (Enumerated


See also:

Changing objects attributes

Text property

TextHAlign property


Standard Properties

These properties are standard properties supported by the Visual Basic itself. See the Visual Basic Language Reference or online Help for documentation of the standard properties.


Runtime property

This property is available only at run-time mode. You can change or read it only using Visual Basic code statements.


Read only property

This property is Read-only.


Write only property

This property is available only for write.


Colors

Color is any expression returning the color code of type Long. Usually colors are specified by using the RGB(..., ..., ...) or QBColor(...) functions. Colors also can be specified with system colors constants from CONSTANT.TXT, a Visual Basic file that specifies system declarations.


Events of the MetaDRAW VBX control
Events of the MetaDRAW Custom Control

Standard events

Click	DblClick	DragDrop	DragOver	GotFocus	LostFocus	KeyDown	KeyUp	KeyPress	MouseDown 	MouseMove	MouseUp

Other events

Change	Picture (object) is changed

DropFile	Occurs when files are dropped from the FileManager

Export	Occurs when an object is exporting to another Device Context

HitObject	Hit mouse onto object

OnHotSpot	Mouse is dragging over a "hotspot" object

Scroll	Picture is scrolled/resized


Change  Event

See Also	Example

Description

Occurs when the picture in the MetaDraw box is changed by adding objects, moving objects, deleting objects, changing properties or number of objects selected.

Syntax

Sub MDraw_Change([Index As Integer,] ChangeType As Integer)

Remarks

The Change event occurs after any change was performed or after last group operation. For example, if you click the mouse on an unselected object, that object become selected, and the previously selected objects are dropped from selection. Only one event will occur independent of how many objects were selected before the click.

The type of change is passed in the ChangeType parameter. This parameter can have the following values:

Constant	Value	Description

CHG_SELECTION	1	Selection was changed for one or more objects.

CHG_OBJECTADD	2	An object was added.

CHG_OBJECTMOVE	3	One or more objects was moved.

CHG_OBJECTRESIZE	4	An object was resized.

CHG_OBJECTOPEN	5	An object or container was opened.

CHG_OBJECTCHANGE	6	Objects attributes were changed.

CHG_OBJECTDELETE	7	One or more objects was deleted.

After entering this event, the Current property contains the handle of the added object (ChangeType parameter is CHG_OBJECTADD) or the handle of the object whose parameters were changed. If changes were applied on several selected objects, the Current property is OBJ_SELECTED.

If ChangeType parameter is CHG_OBJECTDELETE the Current property is OBJ_NULL.

Note	This event can be masked in the EventMask property for different values of the ChangeType parameter.


See also

Changing objects attributes

Current property

EventMask property


DropFile  Event

See Also	Example

Description

Occurs when the user drops one or several files from the File Manager into the MetaDraw control.

Syntax

Sub MDraw_DropFile([Index As Integer,]
X As Integer, Y As Integer,
FName As String, FIndex As Integer)

Remarks

Parameter	Description

X, Y	The client coordinates (in the pixels) of the point where the files were dropped. Use (X, Y) to find out which exact location on the picture the files has hit.

FName	The name of the dropped file. If several files are dropped, the DropFile event is fired either for each file in the list or only for the first one, depending upon the DropMode property setting.

Findex	The index of the currently processed file (Fname) in the list of dropped files. The first file in the list has index 0. When multiple files are processed, FIndex is incremented on every call to the DropFile event. Usually, this parameter is not needed. But, you can decrement it to process the given file again or set it to -1 if no more files should be processed.


See also

Drag-and-Drop operations

DropMode property


Export  Event

See Also	Example

Description

Occurs when objects are exported to another device context (after setting the ExportDC property).

Syntax

Sub MDraw_Export ([Index As Integer,]
ObjNum As Long, State As Integer)

Remarks

Parameter	Description

ObjNum	This parameter depends on the second parameter (State)
* If State parameter is EXP_PROCESS, this parameter specifies the number of the currently exported object (number for first object is 1).
* If State parameter is EXP_START or EXP_FINISH this parameter specifies the total number of exported objects.

State	Determines phase of exporting. This parameter can have the following values:

Constant	Value	Description

EXP_FINISH	0	Finish the exporting of objects.

EXP_START	1	Start the exporting of objects.

EXP_PROCESS	2	Now Exporting for currently object.

The event will be called repeatedly, once at the start of exporting, once for each object being exported, and once to indicate completion.

Before triggering this event, MetaDraw resets the Current property to the handle of object currently being exported. When the State parameter is EXP_START or EXP_FINISH, a value of the Current property is not determined.

The user can interrupt exporting (printing) objects by assigning the State parameter to EXP_FINISH (0) or skip processing for current object by assigning the State parameter to EXP_SKIP (3).


See also

Printing with MetaDraw

ExportDC property

ExportLeft, ExportTop properties

ExportWidth, ExportHeight properties


HitObject  Event

See Also	Example

Description

Occurs when the left mouse button is clicked upon an object whose ObjHitable flag is set.

Syntax

Sub MDraw_HitObject([Index As Integer,]
X As Integer, Y As Integer)

Remarks

This event is triggered when the left mouse button is clicked and the mouse pointer is on or near the object border or on top of the object fill area (if FillStyle is not FS_TRANSPARENT).

When the HitObject event is triggered the Current property contains handle of the topmost object in object stacking order.

The X, Y parameters contain mouse pointer coordinates in the MetaDraw client window in pixels. The Index parameter uniquely identifies a control if it is in a control array.

The MD_ObjectHitTest() API function can be used to receive the next object which is under the specified object and the given mouse coordinates.


See also:

Current property

ObjHitable property

MD_ObjectHitTest() API function


OnHotSpot  Event

See Also	Example

Description

This event occurs when the mouse is moving over an object which has the HotSpot flag set.

Syntax

Sub MDraw_OnHotSpot([Index As Integer,] X As Integer,
Y As Integer, State As Integer)

Remarks

This event occurs only if the HotSpots property is True and it was not masked in the EventMask property.

When the OnHotSpot event is triggered, the Current property contains the handle of the topmost object in the object stacking order which has an ObjHotSpot flag and which lies under the mouse pointer.

The (X, Y) parameters specify the current mouse pointer coordinates in the MetaDraw client window (in pixels). The Coordinates conversion properties can be used to convert its pixel coordinates into picture logical coordinates. The Index parameter uniquely identifies a control if it is in a control array.

The State parameter can be the following values:

Constant	Value	Description

STATE_ENTER	0	Mouse pointer is moved upon object in first time.

STATE_LEAVE	1	Mouse pointer leaves 'hotspot' object.

STATE_DRAG	2	Mouse is moving upon object.

Note	This event will not occur if the mouse pointer leaves the MetaDraw box window or is moving in an area of the window which lies above the MetaDraw box. Be careful, you can receive OnHotSpot event with State parameter as STATE_ENTER and then never receive this event when State is STATE_LEAVE (in the case, for example, when the mouse pointer leaves the MetaDraw box and a new picture was assigned at the time).


See also:

Using Hot-Spot abilities

Current property

EventMask property

HotSpots property

ObjHotSpot property


Scroll Event

See Also	Example

Description

Occurs when the picture size or position is changed, e.g. when the picture is scrolled by the user (using mouse, keyboard or scrollbars) or if PicXOfs/PicYOfs or PicXSize/PicYSize properties are changed programmatically.

Syntax

Sub MDraw_Scroll([Index As Integer])

Remarks

The Scroll event occurs before the actual scrolling/scaling is performed, so the code in this event can check and modify PicXOfs/PicYOfs and PicXSize/PicYSize as required. For example, the following code forces the picture to be scrolled diagonally whenever the user tries to scroll it up or down:

Sub MDraw_Scroll()

    MDraw.PicXOfs = MDraw.PicYOfs

End Sub

Note	No recursion occurs when you change any properties of the given MetaDraw control from inside its Scroll event, because a special internal flag is used to prevent nested calls of this event.


See also:

Picture's coordinates

Displaying and scrolling the picture


Standard Events

These events are the standard events supported by the Visual Basic itself. See the Visual Basic Language Reference or online Help for documentation of the standard events.


MetaDRAW control Methods
Methods of the MetaDRAW Custom Control

See Also

All redefined methods for the MetaDRAW control are listed bellow:

AddItem	Add new element(s) into picture

Clear	Clear the picture (delete all elements)

Refresh	Invalidate and update picture

RemoveItem	Delete specified element(s)

Also you can use standard methods for this control:

Drag	Move	SetFocus	ZOrder


See Also:

MetaDRAW control Properties

MetaDRAW control Events

MetaDRAW API Functions

Convertion Methods


AddItem  Method

See Also	Example

Description

Adds a new object to the current picture in the MetaDraw control box.

Syntax

MDraw.AddItem boundaries$, object_type%

Settings

Parameter	Description

boundaries$	String expression that should contain four integer values: left, top, right, bottom coordinates in the picture logic units.

object_type%	Type of a new object.

Remarks

New objects or container will be added to the current open container. The Current property will contain the handle of the object or container.

If boundaries$ is a null string a new object will have boundaries like the open container.

If the object_type% parameter is OT_CONTAINER, MetaDraw creates an empty container (the boundaries$ parameter is ignored). The new container becomes to be the current open container and all other objects will be added into it.

Using this method you can create any object except OT_BITMAP. For insertion Bitmap in the picture use PictupeClip property. Also you can assign a Bitmap object to the PictureImage property and use AddItem method with object_type% parameter is OT_IMAGE.

Note	MetaDraw doesn't check the boundaries of the added object. The user must be sure what specified coordinates are in the range (PicLeft, PicLeft+PicWidth) and (PicTop, PicTop+PicHeight) by x- and y-axis respectively.


See also

Creating an object

Creating an object using the mouse

Editing objects

RemoveItem method

Action property

ObjType property


Clear  Method

See Also	Example

Description

Destroy (erase) the current picture in the MetaDraw control box.

Syntax

MDraw.Clear

Remarks

After this method is invoked, all objects in the current picture will be deleted, but the picture coordinate properties do not change. To fully destroy the picture, use the following code:

[form].MDraw.PicWidth = 0	' or

[form].MDraw.PicHeight = 0


See also

Creating a New picture

RemoveItem method

Picture property


Refresh  Method

Description

Update the control at run-time.

Syntax

MDraw.Refresh

Remarks

Use this method for a full picture update. This method can be used to refresh the picture while the Redraw property is False.

For more information see the description of the Refresh method in the Microsoft Visual Basic Language Reference.


RemoveItem  Method

See Also	Example

Description

Removes object(s) specified by index, or the Current property, from the current picture in the MetaDraw control box.

Syntax

MDraw.RemoveItem [Reserved_handle]

Settings

The parameter can be one of the following values:

Constant	Value	Description

OBJ_CONTAINER	1	Delete all objects in the current open container. If it is not the main container, then it also will be deleted and the container from the next level up becomes the open container.

OBJ_SELECTED	2	Delete all selected objects.

OBJ_CURRENT	4	Objects for deleting are specified by Current property.

Remarks

If index is OBJ_CURRENT or omitted, an object or group of the objects that are specified by Current property will be deleted. The Current property can contain either a reserved handle or the handle of the object (or container) that should be deleted.


See also

Deleting objects

Creating an object

Current property

AddItem method


VBX MetaDraw API Functions
The MetaDRAW control API Functions

These are some helpful API functions for manipulating objects.

MD_GetBounds	Retrive object(s) boundaries

MD_GetParams	Retrieves objects additional parameters

MD_MoveObjects	Change position of specified objects

MD_ObjectHitTest	Find objects which are located under specified coordinates

MD_SetBounds	Set new object boundaries

MD_SetParams	Sets objects additional parameters

These functions should be declared in the general section of your VB code to use them. For Visual Basic version 2.0 and later these functions can be declared as Sub (subroutine).


MD_GetBounds() API function
MD_GetBounds  API function

See Also	Example

Description

This function returns the boundaries of the object (or selected objects) pointed by the handle specified in the Current property.

Declaration

Declare Function MD_GetBounds Lib "METADRAW.VBX"
(MDraw As Control, rcBounds As VB_RECT,
ByVal crdType As Integer) As Integer

Syntax

result% = MD_GetBounds(MDraw, rcBounds, crdType%)

Parameters

The MD_GetBounds function uses these arguments:

Argument	Description

MDraw	Specifies control name (control handle) the function acts upon.

rcBounds	Rectangle for the receiving boundaries. This variable of the user-defined type which should be declared as VB_RECT.

crdType	Specifies the type of coordinates for the rcBounds parameter.

Returns

An non-zero error code indicates a problem in executing the function.

Remarks

The object(s) boundaries are returned in the structure specified by the rcBounds parameter.

If the Current property specifies a group of selected objects then rcBounds will be filled with the boundaries of the rectangle which is the smallest rectangle that contains all the selected objects.


See Also

Editing objects

ObjLeft, ObjRight, ObjTop, ObjBottom properties

MD_SetBounds() function


MD_GetParams() API function
MD_GetParams  API function

See Also	Example

Description

Returns additional parameters for an object whose handle is specified in the Current property.

Declaration

Declare Function MD_GetParams Lib "METADRAW.VBX"
(MDraw As Control, ByVal FirstPar As Integer,
NumPar As Integer, Params As VB_POINT,
ByVal crdType As Integer) As Integer

Syntax

result% = MD_GetParams(MDraw, 0, pars%, PointArray, crdType%)

Parameters

The MD_GetParams function uses these arguments:

Argument	Description

MDraw	Specifies control name (control handle) the function acts upon.

FirstPar	Specifies first parameter to be retrieved.

NumPar	Specifies the number of the object parameters which can be received (a number of points).

Params	A points array for receiving values (x and y coordinates pairs). This variable is an array of the user-defined type VB_POINT.

crdType	Specifies the type of coordinates for the Params parameter.

Returns

An non-zero error code indicates a problem in executing the function.

Remarks

This function fills a points, array passed in Params argument with additional parameters of an object. The additional parameters of an object is points of a line, a polyline or a polygon, rounded corners in a rounded rectangle and starting or ending points of a sector, a arc or a chord.

Use next values of the FirstPar argument:

-1	Returns total number of the available points in NumPar%. Arguments Params and crdType% are ignored.

0	Specifies first point for a line, a polyline or a polygon, starting point for a sector, a arc or a chord or corners ellipses size for a rounded rectangle.

1	Specifies second point for a line, a polyline or a polygon, ending point for a sector, a arc or a chord.

2..	Specifies next points for a polyline or a polygon.

The Current property should contain a handle of an object.


See Also

Current property

MD_SetParams() function


MD_MoveObjects() API function
MD_MoveObjects  API function

See Also	Example

Description

This function moves the object(s) referenced by the Current property, by specified offsets.

Declaration

Declare Function MD_MoveObjects Lib "METADRAW.VBX"
(MDraw As Control,
ofsX As Integer, ofsY As Integer,
ByVal crdType As Integer) As Integer

Syntax

result% = MD_MoveObjects (MDraw, ofsX%, ofsY%, crdType%)

Parameters

The MD_MoveObjects function uses these arguments:

Argument	Description

MDraw	Specifies control name (control handle) the function acts upon.

ofsX, ofsY	Specifies offset by which object(s) should be moved. It must be a variable name.

crdType	Specifies the type of coordinates for ofsX, ofsY parameters.

Returns

An non-zero error code indicates a problem in executing the function.

Remarks

The type of coordinates in crdType% can be combined with one of the following values:

Constant	Value	Description

CRD_CHECK	&H200	Check offsets while moving object.

CRD_SET	&H400	Set new boundaries after move object.

CRD_CHANGE	&H600	Set new boundaries after move with checking (see CRD_CHECK).

Upon completion, if crdType had CRD_CHECK flag, the parameters ofsX, ofsY contain will contain the maximum allowed value for the offsets.

The function returns value &H7FFF if the object cannot be moved.

See Also

Picture coordinates, Current property.


See Also

Picture's coordinates

Editing objects

Current property


MD_ObjectHitTest() API function
MD_ObjectHitTest  API function

See Also	Example

Description

This function is used to determine the object which is located in the specified coordinates.

Declaration

Declare Function MD_ObjectHitTest Lib "METADRAW.VBX"
(MDraw As Control,
ByVal posX As Integer, ByVal posY As Integer,
ByVal crdType As Integer) As Integer

Syntax

result% = MD_ObjectHitTest (MDraw, posX%, posY%, crdType%)

Parameters

The MD_ObjectHitTest function uses these arguments:

Argument	Description

MDraw	Specifies control name (control handle) the function acts upon.

posX, posY	Coordinates of the test point.

crdType	Specifies the type of coordinates for posX, posY parameters.

Returns

An non-zero error code indicates a problem in executing the function.

Upon return the Current property is set by MetaDraw to either:

*	OBJ_NULL if no object is found at the specified location.

*	The handle of an object at the specified coordinates if such an object exists
This will be the topmost object at the location if the Current property was previously set to OBJ_NULL, or the next highest object under the previously current object otherwise. Repeated calls to this function will therefore cycle through a stack of objects at a given location.

Remarks

The type of coordinates in crdType% can be combined with the following values:

Constant	Value	Description

CRD_SELECTED	&H800	Apply action only for selected objects.

CRD_VISIBLE	&H1000	Apply action only for "Visible" objects.

CRD_HOTSPOT	&H2000	Apply action only for "HotSpot" objects.

CRD_HITABLE	&H4000	Apply action only for "Hitable" objects.

For example, to apply action to selected objects and specify coordinates in client pixels set CrdType to CRD_PIXELS + CRD_SELECTED.


See Also

Picture's coordinates

Using Hot-Spot abilities

Current property

ObjHitable property


MD_SetBounds() API function
MD_SetBounds  API function

See Also	Example

Description

This function sets new boundaries for the object referenced in the Current property.

Declaration

Declare Function MD_SetBounds Lib "METADRAW.VBX"
(MDraw As Control, rcBounds As VB_RECT,
ByVal crdType As Integer) As Integer

Syntax

result% = MD_SetBounds(MDraw, rcBounds, crdType%)

Parameters

The MD_SetBounds function uses these arguments:

Argument	Description

MDraw	Specifies the control name (control handle) the function acts.

rcBounds	Rectangle with new objects boundaries.

crdType	Specifies the type of coordinates for the rcBounds parameter.

Returns

The function returns the value &H7FFF if the object cannot be moved.
An non-zero error code indicates a problem in executing the function.

Upon return if crdType had CRD_CHECK flag, MetaDraw will reset the parameters ofsX and ofsY to the maximum allowed values.

Remarks

The type of coordinates in crdType can be combined with one of the following values to produce a valid crdType:

Constant	Value	Description

CRD_CHECK	&H200	Check offsets while moving object.

CRD_SET	&H400	Set new boundaries after move object.

CRD_CHANGE	&H600	Set new boundaries after move with checking (see CRD_CHECK).


See Also

Picture's coordinates

MD_GetBounds() function

Current property


MD_SetParams() API function
MD_SetParams  API function

See Also	Example

Description

Sets additional parameters for the object referenced in the Current property.

Declaration

Declare Function MD_SetParams Lib "METADRAW.VBX"
(MDraw As Control, ByVal FirstPar As Integer,
ByVal NumPar As Integer, Params As VB_POINT,
ByVal crdType As Integer) As Integer

Syntax

result% = MD_SetParams(MDraw, 1, pars%, PointArray, crdType%)

Parameters

The MD_SetParams function uses these arguments:

Argument	Description

MDraw	Specifies the control name (control handle) the function acts.

FirstPar	Specifies first parameter to be replaced.

NumPar	Specifies how many parameters are passed in Params parameter (a number of points).

Params	A points array with new values.

crdType	Specifies the type of coordinates for the Params parameter.

Returns

An non-zero error code indicates a problem in executing the function.

Remarks

This function replaces additional parameters of an object with a points array passed in the Params argument. The additional parameters of the object is points of a line, a polyline or a polygon, rounded corners in a rounded rectangle and starting or ending points of a sector, a arc or a chord.

For a polyline or a polygon object the type of coordinates in crdType can be combined with the following value:

Constant	Value	Description

CRD_ADD	&H200	Add new points to a polyline or a polygon object. If this mask is not specified, points in a polyline or a polygon will be replaced begining from the FirstPar% point.

Use next values of the FirstPar% argument:

-1	Specifies last point in a polyline or a polygon.

0	Specifies first point for a line, a polyline or a polygon, starting point for a sector, a arc or a chord or corners ellipses size for rounded rectangle.

1	Specifies second point for a line, a polyline or a polygon, ending point for a sector, a arc or a chord.

2...	Specifies next points for a polyline or a polygon.

The Current property should contain a handle of an object.


See Also

Current property

MD_GetParams() function


Type of coordinates

Can be the following values:

Constant	Value	Description

CRD_LOGIC	0	Use global logical coordinates

CRD_LOGIC_LOCAL	2	All coordinates (or offsets) is specified in local (container) logical units.

CRD_PIXELS	4	All coordinates (or offsets) is specified in client pixels


' Values for Action property

Global Const ACT_GROUP = 0
Global Const ACT_UNGROUP = 1
Global Const ACT_SENDBACK = 2
Global Const ACT_MOVEFRONT = 3
Global Const ACT_ONEDOWN = 4
Global Const ACT_ONEUP = 5
Global Const ACT_FLIPHORZ = 6
Global Const ACT_FLIPVERT = 7
Global Const ACT_ROTATELEFT = 8
Global Const ACT_ROTATERIGHT = 9
Global Const ACT_IMAGEINSERT = 10
Global Const ACT_IMAGECOPY = 11
Global Const ACT_IMAGEPICTURE = 12
Global Const ACT_IMAGESWAP = 13
Global Const ACT_DUPLICATE = 14


' Types of the objects

Global Const OT_CONTAINER = 0
Global Const OT_LINE = 1
Global Const OT_RECTANGLE = 2
Global Const OT_ROUNDRECT = 3
Global Const OT_ELLIPSE = 4
Global Const OT_ARC = 5
Global Const OT_PIE = 6
Global Const OT_CHORD = 7
Global Const OT_POLYLINE = 8
Global Const OT_POLYGON = 9
Global Const OT_TEXT = 10
Global Const OT_BITMAP = 11
Global Const OT_IMAGE = 12


' Values for AutoScale property

Global Const SCALE_NONE = 0
Global Const SCALE_RESIZE = 1
Global Const SCALE_FIT = 2
Global Const SCALE_ORIG = 3


' Values for BackStyle property

Global Const TRANSPARENT = 0
Global Const OPAQUE = 1


' Values for Change event parameter

Global Const CHG_NONE = 0
Global Const CHG_SELECTION = 1
Global Const CHG_OBJECTADD = 2
Global Const CHG_OBJECTMOVE = 3
Global Const CHG_OBJECTRESIZE = 4
Global Const CHG_OBJECTOPEN = 5
Global Const CHG_OBJECTCHANGE = 6
Global Const CHG_OBJECTDELETE = 7


' Values for Current property

Global Const OBJ_NULL = -1
Global Const OBJ_CONTAINER = 1
Global Const OBJ_SELECTED = 2
Global Const OBJ_SEL_ATTR = 3
Global Const OBJ_CURR_ATTR = 4
Global Const OBJ_CONT_MAIN = 5


' Values for DrawMode property

Global Const R2_BLACK = 1
Global Const R2_NOTMERGEPEN = 2
Global Const R2_MASKNOTPEN = 3
Global Const R2_NOTCOPYPEN = 4
Global Const R2_MASKPENNOT = 5
Global Const R2_NOT = 6
Global Const R2_XORPEN = 7
Global Const R2_NOTMASKPEN = 8
Global Const R2_MASKPEN = 9
Global Const R2_NOTXORPEN = 10
Global Const R2_NOP = 11
Global Const R2_MERGENOTPEN = 12
Global Const R2_COPYPEN = 13
Global Const R2_MERGEPENNOT = 14
Global Const R2_MERGEPEN = 15
Global Const R2_WHITE = 16


' Values for DrawMode property

Global Const FDROP_NONE = 0
Global Const FDROP_FIRST = 1
Global Const FDROP_ALL = 2


' Values for EditFlags property

Global Const EFLG_SELECT = 1
Global Const EFLG_SELSHIFT = 2
Global Const EFLG_SELGROUP = 4
Global Const EFLG_DRAWSCEL = 8
Global Const EFLG_MOVE = &H10
Global Const EFLG_RESIZE = &H20
Global Const EFLG_OPEN = &H40


' Values for EditMode property

Global Const ED_VIEW = 0
Global Const ED_LINE = 1
Global Const ED_RECT = 2
Global Const ED_ROUND = 3
Global Const ED_ELLIPSE = 4
Global Const ED_ARC = 5
Global Const ED_PIE = 6
Global Const ED_CHORD = 7
Global Const ED_POLYLINE = 8
Global Const ED_POLYGON = 9
Global Const ED_TEXT = 10
Global Const ED_SELECT = 11
Global Const ED_IMAGE = 12


' Values for EventMask property

Global Const EMSK_HITOBJECT = 1
Global Const EMSK_ONHOTSPOT = 2
Global Const EMSK_SELECT = &H10
Global Const EMSK_ADD = &H20
Global Const EMSK_MOVE = &H40
Global Const EMSK_RESIZE = &H80
Global Const EMSK_OPEN = &H100


' Values for Export event parameter

Global Const EXP_FINISH = 0
Global Const EXP_START = 1
Global Const EXP_PROCESS = 2
Global Const EXP_SKIP = 3


' Values for FillStyle property

Global Const FS_SOLID = 0
Global Const FS_TRANSPARENT = 1
Global Const FS_HORIZONTAL = 2
Global Const FS_VERTICAL = 3
Global Const FS_FDIAGONAL = 4
Global Const FS_BDIAGONAL = 5
Global Const FS_CROSS = 6
Global Const FS_DIAGCROSS = 7
Global Const FS_PATTERN = 8


' Values for FontStyle property

Global Const FSTL_FIXED = 0
Global Const FSTL_PROPOR = 1
Global Const FSTL_SCALABLE = 2


' Values for LineStyle property

Global Const PS_SOLID = 0
Global Const PS_DASH = 1
Global Const PS_DOT = 2
Global Const PS_DASHDOT = 3
Global Const PS_DASHDOTDOT = 4
Global Const PS_NULL = 5
Global Const PS_INSIDEFRAME = 6


' VB_RECT type declaration

Type VB_RECT
  Left As Integer
  Top As Integer
  Right As Integer
  Bottom As Integer
End Type


' VB_POINT type declaration

Type VB_POINT
  x As Integer
  x As Integer
End Type


' Type of the coordinates

Global Const CRD_LOGIC = 0
Global Const CRD_LOGIC_LOCAL = 2
Global Const CRD_PIXELS = 4


' Objects mask coordinates type

Global Const CRD_SELECTED = &H800
Global Const CRD_VISIBLE = &H1000
Global Const CRD_HOTSPOT = &H2000
Global Const CRD_HITABLE = &H4000


' Mask for coordinates type

Global Const CRD_CHECK = &H200
Global Const CRD_SET = &H400
Global Const CRD_CHANGE = &H600


' Mask for coordinates type

Global Const CRD_ADD = &H200


' Declaration for MD_GetBounds() function

Declare Function MD_GetBounds Lib "METADRAW.VBX" (MDraw As Control, rcBounds As VB_RECT, ByVal crdType As Integer) As Integer


' Declaration for MD_GetParams() function

Declare Function MD_GetParams Lib "METADRAW.VBX" (MDraw As Control, ByVal FirstPar As Integer, NumPar As Integer, Params As VB_POINT, ByVal crdType As Integer) As Integer


' Declaration for MD_MoveObjects() function

Declare Function MD_MoveObjects Lib "METADRAW.VBX" (MDraw As Control, ofsX As Integer, ofsY As Integer, ByVal crdType As Integer) As Integer


' Declaration for MD_ObjectHitTest() function

Declare Function MD_ObjectHitTest Lib "METADRAW.VBX" (MDraw As Control, ByVal posX As Integer, ByVal posY As Integer, ByVal crdType As Integer) As Integer


' Declaration for MD_SetBounds() function

Declare Function MD_SetBounds Lib "METADRAW.VBX" (MDraw As Control, rcBounds As VB_RECT, ByVal crdType As Integer) As Integer


' Declaration for MD_SetParams() function

Declare Function MD_SetParams Lib "METADRAW.VBX" (MDraw As Control, ByVal FirstPar As Integer, ByVal NumPar As Integer, Params As VB_POINT, ByVal crdType As Integer) As Integer


' Values for MousePointer property

Global Const MPTR_DEFAULT = 0
Global Const MPTR_ARROW = 1
Global Const MPTR_CROSS = 2
Global Const MPTR_HBEAM = 3
Global Const MPTR_ICON = 4
Global Const MPTR_SIZE = 5
Global Const MPTR_SIZENESW = 6
Global Const MPTR_SIZENS = 7
Global Const MPTR_SIZENWSE = 8
Global Const MPTR_SIZEWE = 9
Global Const MPTR_UPARROW = 10
Global Const MPTR_HOURGLASS = 11
Global Const MPTR_NODROP = 12
Global Const MPTR_USER = 15
Global Const MPTR_MOVE = 16
Global Const MPTR_SCROLL = 17
Global Const MPTR_HOTSPOT = 18
Global Const MPTR_DRAWPEN = 19
Global Const MPTR_VIEW = 20
Global Const MPTR_LINE = 21
Global Const MPTR_RECT = 22
Global Const MPTR_ROUND = 23
Global Const MPTR_ELLIPSE = 24
Global Const MPTR_ARC = 25
Global Const MPTR_PIE = 26
Global Const MPTR_CHORD = 27
Global Const MPTR_POLYLINE = 28
Global Const MPTR_POLYGON = 29
Global Const MPTR_TEXT = 30
Global Const MPTR_SELECT = 31
Global Const MPTR_IMAGE = 32


' Values for ObjCount property

Global Const OBJ_CONTAINER = 1
Global Const OBJ_SELECTED = 2
Global Const OBJ_CURRENT = 4
Global Const OBJ_CONT_MAIN = 5


' Values for ObjMove property

Global Const MOVE_NEXT = 0
Global Const MOVE_PREV = 1
Global Const MOVE_FIRST = 2
Global Const MOVE_LAST = 3
Global Const MOVE_PARENT = 4
Global Const MOVE_CHILD_FIRST = 5
Global Const MOVE_CHILD_LAST = 6
Global Const MOVE_SEL_NEXT = 7
Global Const MOVE_SEL_PREV = 8
Global Const MOVE_SEL_FIRST = 10
Global Const MOVE_SEL_LAST = 11
Global Const MOVE_OPENED = 12
Global Const MOVE_CONT_MAIN = 13
Global Const MOVE_CONT_FIRST = 14
Global Const MOVE_CONT_LAST = 15


' Values for OnHotSpot event parameter

Global Const STATE_ENTER = 0
Global Const STATE_LEAVE = 1
Global Const STATE_DRAG = 2


' Values for OpenDraw property

Global Const OPDR_FULL = 0
Global Const OPDR_CONTAINER = 1
Global Const OPDR_HATCHED = 2


' Values for PictureType property

Global Const PICTYPE_NONE = 0
Global Const PICTYPE_METAFILE = 1
Global Const PICTYPE_BITMAP = 2
Global Const PICTYPE_ICON = 3
Global Const PICTYPE_PLAINWMF = 4


' Values for RemoveItem method parameter

Global Const OBJ_CONTAINER = 1
Global Const OBJ_SELECTED = 2
Global Const OBJ_CURRENT = 4


' Values for Repaint property

Global Const PAINT_NORMAL = 0
Global Const PAINT_BUFFERED = 1


' Values for ScrollBars property

Global Const BAR_NONE = 0
Global Const BAR_AUTO = 1
Global Const BAR_ALWAYS = 2


' Values for TextHAlign property

Global Const TXT_LEFT = 0
Global Const TXT_CENTER = 1
Global Const TXT_RIGHT = 2


' Values for TextVAlign property

Global Const TXT_TOP = 0
Global Const TXT_CENTER = 1
Global Const TXT_BOTTOM = 2


' Trappable errors constants

Global Const MDERR_CANTSETPROP = 387
Global Const MDERR_NOSELECTION = 24000
Global Const MDERR_INVALIDHANDLE = 24001
Global Const MDERR_INVALIDTYPE = 24002
Global Const MDERR_INVALIDINDEX = 24003
Global Const MDERR_INVALIDPARAM = 24004
Global Const MDERR_BADMETAFILE = 24005
Global Const MDERR_NOTCONTAINER = 24006
Global Const MDERR_NOTTEXT = 24007
Global Const MDERR_NOPICTURE = 24008
Global Const MDERR_CANTDELETE = 24009
Global Const MDERR_CANTOPEN = 24010


' Action Property  example

' The example adds the picture determined by PictureImage property to the
' MetaDraw control as container and flips its vertically.

' To try this example, add a MetaDraw control into a new form, assign a
' metafile to the PictureImage property, paste the following code into the
' Declarations section of the form. Then press F5 and click the control.

Sub MDraw1_Click()
    MDraw1.Action = 10  ' ACT_IMAGEINSERT
    MDraw1.Action = 7   ' ACT_FLIPVERT
End Sub


' Create a new Picture  example

' The example shows how the user can create a new picture and then
' display it using the AutoScale property.

' To try this example, add a MetaDraw control into a new form, assign
' a picture to the PictureImage property, paste the code into the Declarations
' section of a form.  Then press F5 and click the control, resize the form
' and watch for changes or press the specified keys.

Sub CreateNewPicture ()
    Dim Cont&, bnd As VB_RECT
    MDraw1.picWidth = 0
    MDraw1.OrigWidth = Int(Rnd * 4320) + 1440
    MDraw1.OrigHeight = Int(Rnd * 4320) + 1440
    MDraw1.picWidth = Int(Rnd * 200) + 10
    MDraw1.picHeight = Int(Rnd * 200) + 10
    bnd.left = 0: bnd.top = 0
    bnd.right = MDraw1.picWidth
    bnd.bottom = MDraw1.picHeight
    MDraw1.AddItem "", OT_CONTAINER
    Cont& = MDraw1.Current
    MDraw1.Action = ACT_IMAGEINSERT     ' Insert from PictureImage
    MDraw1.Current = OBJ_CONTAINER
    MDraw1.ObjOpened = False
    MDraw1.AddItem "", OT_CONTAINER
    MDraw1.AddItem "10 0", OT_TEXT
    MDraw1.Text = "'F' - Fit to window"
    MDraw1.AddItem "10 30", OT_TEXT
    MDraw1.Text = "'R' - Resize with window"
    MDraw1.AddItem "10 60", OT_TEXT
    MDraw1.Text = "'O' - Set original size"
    MDraw1.AddItem "10 100", OT_TEXT
    MDraw1.Text = "'N' - New picture"
    MDraw1.AddItem "10 130", OT_TEXT
    MDraw1.Text = "'S' - Save to PictureImage"
    bnd.left = 0: bnd.top = 0
    bnd.right = MDraw1.picWidth
    MDraw1.ObjMove = MOVE_CONT_OPENED
    Call MD_SetBounds(MDraw1, bnd, CRD_LOGIC)
    MDraw1.Current = Cont&      ' Open container with picture
    MDraw1.ObjOpened = True
    MDraw1.PictureChanged = False
    MDraw1.AutoScale = SCALE_ORIG
End Sub

Sub Form_Load ()
    MDraw1.EditMode = ED_ELLIPSE
    Call CreateNewPicture
End Sub

Sub Form_Resize ()
    MDraw1.Align = 1    ' Align Top
    MDraw1.Height = Me.ScaleHeight
End Sub

Sub Form_Unload (Cancel As Integer)
    If MDraw1.PictureChanged Then
        MsgBox "Picture has been changed. Double-click the control to clear it."
        Cancel = True
    End If
End Sub

Sub MDraw1_DblClick ()
    MDraw1.Clear
End Sub

Sub MDraw1_KeyPress (KeyAscii As Integer)
    Select Case KeyAscii
    Case 70, 102    ' F, f
      MDraw1.AutoScale = SCALE_FIT
    Case 82, 114    ' R, r
      MDraw1.AutoScale = SCALE_RESIZE
    Case 79, 111    ' O, o
      MDraw1.AutoScale = SCALE_ORIG
    Case 78, 110    ' N, n
      Call CreateNewPicture
    Case 83, 115    ' S, s
      MDraw1.Current = OBJ_CONTAINER
      MDraw1.ObjSelected = True
      MDraw1.PictureImage = MDraw1.PictureClip
    End Select
End Sub


' Colors Properties  Example

' The example resets colors of previously created objects (rectangle and text)
' randomly each the left mouse click.

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control. Then press F5 and click the control.

Sub Form_Load ()
  MDraw1.AddItem "50 50 500 400", 2    ' OT_RECTANGLE
  MDraw1.BackStyle = 1                 ' Opaque
  MDraw1.LineWidth = -30               ' Set border width
  MDraw1.AddItem "280 200 280 200", 10 ' OT_TEXT
  MDraw1.TextHAlign = 1
  MDraw1.Text = "Text insize Rectangle"
  MDraw1.BackStyle = 1                 ' Opaque
End Sub

Sub MDraw1_Click ()
    MDraw1.ObjMove = 14  ' Move Current to the Rectangle
    MDraw1.FillStyle = 3 + Int(Rnd * 5)
    MDraw1.BackColor = Int(Rnd * &HFFFFFF)
    MDraw1.FillColor = Int(Rnd * &HFFFFFF)
    MDraw1.LineColor = Int(Rnd * &HFFFFFF)
    MDraw1.ObjMove = 0   ' Move Current to the Text object
    MDraw1.BackColor = Int(Rnd * &HFFFFFF)
    MDraw1.TextColor = Int(Rnd * &HFFFFFF)
End Sub


' Simple "Preview"  Example

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control with a picture assigned to the Picture
' property.  Then press F5 and click the control.

Sub MDraw1_Click ()
    Dim ratio As Single, w%, h%
    ratio = MDraw1.OrigWidth / MDraw1.OrigHeight
    w% = (MDraw1.Width * 9) / 10
    h% = (MDraw1.Height * 9) / 10
    If (h% * ratio) < w% Then
        w% = h% * ratio
    Else
        h% = w% / ratio
    End If
    MDraw1.Redraw = False       ' Disable auto redraw
    MDraw1.ScrollBars = 0       ' Disable scroll bars
    MDraw1.ScrollCheck = False  ' Disable offsets checking
    MDraw1.PicBorderColor = RGB(127, 127, 127)
    MDraw1.picXSize = w%
    MDraw1.picYSize = h%
    MDraw1.picXOfs = -(MDraw1.Width - w%) / 2
    MDraw1.picYOfs = -(MDraw1.Height - h%) / 2
    MDraw1.Redraw = True        ' Enable auto redraw

    MDraw1.ScrollMouse = False  ' Disable mouse scrolling
    MDraw1.ShowInvisible = True ' Show all objects
End Sub


' Select objects  Example

' The example selects all ellipses in the picture loaded in the MetaDraw
' control when the left mouse button is clicked. And deletes theirs after the
' mouse double-click.

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control with a loaded picture.
' Then press F5 and click the control.

Sub MDraw1_Click ()
  MDraw1.Current = 1            ' OBJ_CONTAINER
  MDraw1.ObjSelected = False    ' Drop old selection
' Set Current property to first object in the current
' container and scan the objects list of the container
  MDraw1.ObjMove = 14           ' MOVE_CONT_FIRST
  While MDraw1.Current > 0      ' OBJ_NULL
    If MDraw1.ObjType = 4 Then  ' Is it an ellipse?
      MDraw1.ObjSelected = True ' Set selection if it is an ellipse
    End If
    MDraw1.ObjMove = 0          ' MOVE_NEXT Move to the next object
  Wend
End Sub

Sub MDraw1_DblClick ()
    If MDraw1.ObjCount(2) > 0 Then  ' Is there selected objects
      MDraw1.RemoveItem 2           ' OBJ_SELECTED Delete selected
    End If
End Sub


' Printing a picture  Example

' The example prints a picture mixed with text on the page when
' the user clicks the control.

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control with a loaded picture and a label control named Label1.
' Then press F5 and click the control.

Dim total As Long

Sub MDraw1_Click ()
    MDraw1.MousePointer = 11    ' MPTR_HOURGLASS wait cursor
    MDraw1.Current = 5          ' OBJ_CONT_MAIN the whole picture
    Printer.FontName = "Arial"
    Printer.FontSize = 16
    Printer.ForeColor = 0
    Printer.ScaleMode = 3       ' Pixels
    Printer.Print ""            ' Initialize the printer
    Printer.Print "This picture was printed from MetaDRAW"
    MDraw1.ExportLeft = 720 / Printer.TwipsPerPixelX
    MDraw1.ExportTop = Printer.CurrentY + 720 / Printer.TwipsPerPixelY
    MDraw1.ExportWidth = MDraw1.OrigWidth * Screen.TwipsPerPixelX / Printer.TwipsPerPixelX
    MDraw1.ExportHeight = 0     ' Calculate automatically
    MDraw1.ExportDC = Printer.hDC
    Printer.NewPage
    Printer.EndDoc
    MDraw1.MousePointer = 0     ' Normal Cursor
End Sub

Sub MDraw1_Export (ObjNum As Long, State As Integer)
    Select Case State
    Case 1      ' EXP_START
      total = ObjNum
      Label1 = "Start printing ..."
    Case 0      ' EXP_FINISH
      Label1 = ObjNum & " object(s) have been printed"
    Case 2      ' EXP_PROCESS
      If total > 0 Then
        Label1 = "Printing: " & Int(ObjNum / total * 100) & "%"
        Label1.Refresh
      End If
    End Select
End Sub


' Drag & Drop Files  Example

' The example receives files (pictures) from FileManager.

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control.  Then press F5 and click the control.

Sub MDraw1_Click ()
    Dim res%
    MDraw1.DropMode = 2     ' Enable Dropping All files
    res% = Shell("winfile.exe", 4)
End Sub

Sub MDraw1_DropFile (X As Integer, Y As Integer, FName As String, FIndex As Integer)
    On Error Resume Next: Err = 0
    If (FIndex = 0) Then
      MDraw1.Picture = LoadPicture(FName)
    Else
      MDraw1.PictureClip = LoadPicture(FName)
    End If
    If Err Or FIndex > 2 Then FIndex = -1
    MDraw1.DropMode = 0         ' Disable Dropping
End Sub


' AddItem Method  Example

' The example creates a container that contains three objects and a pie object.

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control.  Then press F5.

Sub Form_Load ()

    Dim hnd&

    MDraw1.AddItem "", 0        ' OT_CONTAINER Create a container

    hnd& = MDraw1.Current       ' Save its handle

    ' Insert some objects into the new container

    MDraw1.AddItem "100 100 500 500", 2  ' OT_RECTANGLE

    MDraw1.AddItem "200 150 400 300", 4  ' OT_ELLIPSE

    MDraw1.FillColor = RGB(255, 0, 0)    ' Change fill color

    MDraw1.AddItem "150 400 450 400", 1  ' OT_LINE

    MDraw1.LineStyle = 3                 ' Change line style

    MDraw1.Current = hnd&

    MDraw1.ObjOpened = False             ' Close our container

    MDraw1.AddItem "300 250 600 600", 6  ' OT_PIE add a pie

    MDraw1.EditMode = 11                 ' ED_EDIT   Allow editing

End Sub


' RemoveItem Method  Example

' The example creates an accidental object when the right mouse button is
' clicked. Pressing the "space" key removes all objects except ellipses.
' Pressing the "Enter" key deletes all selected objects. To clear whole
' picture double-click the control.

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control (the project must contain METADRAW.VBX and METADRAW.BAS files).  Then press F5.

Sub Form_Load ()
    MDraw1.EditMode = ED_EDIT
    MDraw1.EditFlags = EFLG_SELECT + EFLG_SELSHIFT + EFLG_SELGROUP
    MDraw1.EditFlags = MDraw1.EditFlags + EFLG_MOVE

    ' Switch to edit mode (only for selecting and moving)

End Sub

' Clear the picture

Sub MDraw1_DblClick ()
    MDraw1.Clear
End Sub

' Delete some objects

Sub MDraw1_KeyPress (KeyAscii As Integer)
    Select Case KeyAscii
    Case 13, 83, 115    ' Enter, "S" or "s"
      If MDraw1.ObjCount(OBJ_SELECTED) > 0 Then
        MDraw1.RemoveItem OBJ_SELECTED
      End If
    Case 32             ' Space
      Dim nxt&, cur&
      MDraw1.ObjMove = MOVE_CONT_FIRST
      While MDraw1.Current > OBJ_NULL
        If MDraw1.ObjType <> OT_ELLIPSE Then
          cur& = MDraw1.Current
          MDraw1.ObjMove = MOVE_NEXT
          nxt& = MDraw1.Current
          MDraw1.Current = cur&
          MDraw1.RemoveItem OBJ_CURRENT
          MDraw1.Current = nxt&
        Else
          MDraw1.ObjMove = MOVE_NEXT
        End If
      Wend
    End Select
End Sub

' Create a new random object

Sub MDraw1_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim w%, h%, bnd As VB_RECT
    If Button = 2 Then
      w% = Int(Rnd * 400): h% = Int(Rnd * 300)
      bnd.left = X / Screen.TwipsPerPixelX - w% \ 2
      bnd.top = Y / Screen.TwipsPerPixelY - h% \ 2
      bnd.right = bnd.left + w%
      bnd.bottom = bnd.top + h%
      MDraw1.AddItem "", Int(Rnd * 6) + 1
      Call MD_SetBounds(MDraw1, bnd, CRD_SET + CRD_PIXELS)
      MDraw1.FillColor = Int(Rnd * &HFFFFFF)
    End If
End Sub


' Changing boundaries  Example

' The example allows you to create objects whose type is specified by
' previous pressed key:
'	"e"	- Create an ellipses;
'	"r"	- Create a rectangles;
'	"p"	- Create a polylines.
' Pressing of "Esc" key toggles the control to selection mode. You can
' select an object by click the left mouse button on it (use the "SHIFT" key
' for multiply selection). Pressing of "Space" key draws a frame rectangle
' around selected objects. Use the arrows keys and the right mouse
'  button to scroll picture

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control (the project must include METADRAW.VBX
' and METADRAW.BAS files).  Then press F5.

Sub Form_Load ()
    MDraw1.EditMode = ED_ROUND
    MDraw1.ScrollKeyboard = True
End Sub

Sub MDraw1_KeyPress (KeyAscii As Integer)
    Select Case KeyAscii
    Case 32
      Dim bnd As VB_RECT, bounds$
      ' Remove old frame rectangles
      MDraw1.ObjMove = MOVE_CONT_FIRST
      While MDraw1.Current > OBJ_VALID
        If MDraw1.ObjTag = "frame" Then
          MDraw1.RemoveItem OBJ_CURRENT
      ' MDraw1.Current points to the next object in the objects list
        Else
          MDraw1.ObjMove = MOVE_NEXT
        End If
      Wend
      MDraw1.Current = OBJ_SELECTED
      Call MD_GetBounds(MDraw1, bnd, CRD_LOGIC)
      bounds$ = bnd.left & " " & bnd.top
      bounds$ = bounds$ & " " & bnd.right & " " & bnd.bottom
      MDraw1.AddItem bounds$, OT_RECTANGLE
      MDraw1.FillStyle = 1      ' Transparent
      MDraw1.LineColor = RGB(255, 255, 255)
      MDraw1.LineWidth = 0      ' One pixel width
      MDraw1.LineStyle = 2      ' Dotted line
      MDraw1.DrawMode = 7       ' XOR
      MDraw1.ObjTag = "frame"
    Case 69, 101                ' "E", "e" - ellipse
      MDraw1.EditMode = ED_ELLIPSE
    Case 82, 114                ' "R", "r" - rectangle
      MDraw1.EditMode = ED_RECT
    Case 80, 112                ' "P", "p" - polyline
      MDraw1.EditMode = ED_POLYLINE
    Case 27
      MDraw1.EditMode = ED_EDIT
    Case Else
      Beep
    End Select
End Sub


' Using HotSpots  Example

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control (the project must include METADRAW.VBX
' and METADRAW.BAS files).  Then press F5.

Dim info&, mode&

Sub Form_Load ()
    Dim i%
    MDraw1.EventMask = 0    ' Disable all MetaDraw's events
    For i% = 0 To 7         ' Create painting toolbar
      MDraw1.AddItem 30 + i% * 60 & " 100 " & 75 + i% * 60 & " 160", i% + 1
      MDraw1.ObjHotSpot = True
      MDraw1.ObjHitable = True
      Select Case i%
      Case 0
        MDraw1.ObjTag = " Line "
      Case 1
        MDraw1.ObjTag = " Rectangle "
      Case 2
        MDraw1.ObjTag = " Rounded rectangle "
      Case 3
        MDraw1.ObjTag = "n Ellipse "
      Case 4
        MDraw1.ObjTag = "n Arc "
      Case 5
        MDraw1.ObjTag = " Sector "
      Case 6
        MDraw1.ObjTag = " Chord "
      Case 7
        MDraw1.ObjTag = " Polyline "
      End Select
      MDraw1.FillColor = RGB((i% And 1) * 255, (i% \ 2 And 1) * 255, (i% \ 4) * 255)
    Next i%

    MDraw1.AddItem "10 10", OT_TEXT
    info& = MDraw1.Current
    MDraw1.Text = "There are no objects"
    MDraw1.TextColor = RGB(255, 0, 0)
    MDraw1.BackStyle = 0        ' Transparent

    MDraw1.AddItem "10 10", OT_TEXT
    mode& = MDraw1.Current
    MDraw1.Text = "Tool bar info"
    MDraw1.TextColor = RGB(255, 255, 0)
    MDraw1.BackColor = RGB(0, 0, 255)
    MDraw1.BackStyle = 1        ' Opague
    MDraw1.ObjVisible = False   ' Hide

' Create frame rectangle around "toolbar"
    MDraw1.AddItem "15 85 515 175", OT_RECTANGLE
    MDraw1.FillStyle = 1
    MDraw1.LineWidth = 0
    MDraw1.LineColor = 0

    MDraw1.HotSpots = True      ' Enable HotSpots
    MDraw1.MarkerSize = 0       ' Don't show markers
    MDraw1.EventMask = EMSK_ADD + EMSK_ONHOTSPOT + EMSK_HITOBJECT
    ' Enable only Change (CHG_OBJECTADD), HitObject and OnHotSpot events
End Sub

Sub MDraw1_Change (ChangeType As Integer)
    If (ChangeType = CHG_OBJECTADD) Then
      MDraw1.Current = info&
      MDraw1.Text = (MDraw1.ObjCount(OBJ_CONT_MAIN) - 11) & " object(s) have been added"
      MDraw1.EditMode = ED_VIEW ' Switch to HotSpot Mode
    End If
End Sub

Sub MDraw1_HitObject (X As Integer, Y As Integer)
    Dim Cl&
    MDraw1.EditMode = MDraw1.ObjNumber
    MDraw1.EditFlags = IIf(MDraw1.EditMode <> ED_LINE, EFLG_DRAWSCEL, 0)
    Cl& = MDraw1.FillColor
    MDraw1.Current = OBJ_CUR_ATTR
    MDraw1.FillColor = Cl&
    MDraw1.LineColor = Not Cl& And &HFFFFFF
    MDraw1.LineWidth = Int(Rnd * 10)
End Sub

Sub MDraw1_OnHotSpot (X As Integer, Y As Integer, State As Integer)
    Dim s$
    s$ = " Use the mouse to create a" + MDraw1.ObjTag
    MDraw1.Current = info&
    MDraw1.ObjVisible = (State = STATE_LEAVE)
    MDraw1.Current = mode&
    MDraw1.ObjVisible = (State <> STATE_LEAVE)
    MDraw1.Text = s$
End Sub


' MoveObjects() function  Example

'The example shows how you can move selected objects in the left-upper corner
' ("Enter" key) or in the right-bottom corner ("Space" key).

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control with loaded picture and a label control named Label1. The project must
' include METADRAW.VBX and METADRAW.BAS files.  Then press F5.

Sub Form_Load ()
    Me.ScaleMode = 3             ' Pixels
    MDraw1.EditMode = ED_EDIT
    MDraw1.ScrollMouse = True    ' Enable mouse scrolling
    MDraw1.ScrollKeyboard = True ' Enable scrolling with keyboard
    MDraw1.picXSize = MDraw1.Width * 1.5
    MDraw1.picYSize = MDraw1.Height * 1.5
End Sub

Sub MDraw1_KeyPress (KeyAscii As Integer)
    Dim ofsX%, ofsY%
    Select Case KeyAscii
    Case 32
      If MDraw1.ObjCount(OBJ_SELECTED) > 0 Then
        MDraw1.Current = OBJ_SELECTED
        ofsX% = MDraw1.ObjRight     ' Right bounds in log. units
        ofsX% = MDraw1.LogicToClientX(ofsX%)   ' Convert to pixels
        ofsX% = MDraw1.ClientWidth - ofsX%
        ofsY% = MDraw1.ObjBottom    ' Bottom bounds in log. units
        ofsY% = MDraw1.LogicToClientY(ofsY%)   ' Convert to pixels
        ofsY% = MDraw1.ClientHeight - ofsY%
        Call MD_MoveObjects(MDraw1, ofsX%, ofsY%, CRD_PIXELS + CRD_CHANGE)
      End If
    Case 13
      If MDraw1.ObjCount(OBJ_SELECTED) > 0 Then
        MDraw1.Current = OBJ_SELECTED
        ofsX% = -MDraw1.LogicToClientX(MDraw1.ObjLeft)
        ofsY% = -MDraw1.LogicToClientY(MDraw1.ObjTop)
        Call MD_MoveObjects(MDraw1, ofsX%, ofsY%, CRD_PIXELS + CRD_CHANGE)
      End If
    End Select
End Sub

Sub MDraw1_MouseDown (Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim res%
    MDraw1.Current = OBJ_NULL
    x = x / Screen.TwipsPerPixelX
    y = y / Screen.TwipsPerPixelY
    res% = MD_ObjectHitTest(MDraw1, x, y, CRD_PIXELS)
    If MDraw1.Current > OBJ_NULL Then
      Select Case MDraw1.ObjType
      Case OT_CONTAINER
        Label1 = "Container"
      Case OT_LINE
        Label1 = "Line"
      Case OT_RECTANGLE
        Label1 = "Rectangle"
      Case OT_ROUNDRECT
        Label1 = "Rounded Rectangle"
      Case OT_ELLIPSE
        Label1 = "Ellipse"
      Case OT_ARC
        Label1 = "Arc"
      Case OT_PIE
        Label1 = "Sector"
      Case OT_CHORD
        Label1 = "Chord"
      Case OT_POLYLINE
        Label1 = "PolyLine"
      Case OT_POLYGON
        Label1 = "Polygon"
      Case OT_TEXT
        Label1 = "Tetx"
      Case OT_BITMAP
        Label1 = "Bitmap"
      End Select
      Label1 = "The mouse is dragging over the " & Label1
    Else
      Label1 = "There are no objects"
    End If
End Sub


' Scroll Event  Example

' The example shows how you can use Scroll event to limit picture scrolling.
' The object inside the picture will never lie outside of the client area.

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control.  Then press F5.

Sub Form_Load ()
    Me.ScaleMode = 3            ' Pixels
    MDraw1.ScrollKeyboard = True
    MDraw1.ScrollMouse = True
    MDraw1.AddItem "500 500 600 600", 4 ' OT_ELLIPSE

    MDraw1.ObjSelected = True           ' Select it

    ' Make the visible picture sizes larger than the client area

    MDraw1.picXSize = MDraw1.Width * 1.5
    MDraw1.picYSize = MDraw1.Height * 1.5
End Sub

Sub MDraw1_Scroll ()

    MDraw1.Current = 2      ' OBJ_SELECTED

    If MDraw1.LogicToClientX(MDraw1.ObjLeft) < 0 Then

        MDraw1.picXOfs = MDraw1.picXOfs + MDraw1.LogicToClientX(MDraw1.ObjLeft)

    Else

      If MDraw1.LogicToClientX(MDraw1.ObjRight) > MDraw1.ClientWidth Then

        MDraw1.picXOfs = MDraw1.picXOfs - (MDraw1.ClientWidth - MDraw1.LogicToClientX(MDraw1.ObjRight))

      End If

    End If

    If MDraw1.LogicToClientY(MDraw1.ObjTop) < 0 Then

        MDraw1.picYOfs = MDraw1.picYOfs + MDraw1.LogicToClientY(MDraw1.ObjTop)

    Else

      If MDraw1.LogicToClientY(MDraw1.ObjBottom) > MDraw1.ClientHeight Then

        MDraw1.picYOfs = MDraw1.picYOfs - (MDraw1.ClientHeight - MDraw1.LogicToClientY(MDraw1.ObjBottom))

      End If

    End If

End Sub


' hDC Property  Example

' The example adds some objects using the hDC property.

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control.  Then press F5.

Declare Sub Ellipse Lib "GDI.EXE" (ByVal hDC As Integer, ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer)

Declare Sub Rectangle Lib "GDI.EXE" (ByVal hDC As Integer, ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer)

Declare Sub Polygon Lib "GDI.EXE" (ByVal hDC As Integer, Points As Integer, ByVal count As Integer)

Sub MDraw1_KeyPress (KeyAscii As Integer)

    Dim hDC As Integer

    ReDim Points(10) As Integer

    hDC = MDraw1.hDC

    Call Ellipse(hDC, 200, 300, 800, 700)

    Call Rectangle(hDC, 300, 400, 700, 600)

    Points(0) = 100: Points(1) = 100

    Points(2) = 200: Points(3) = 300

    Points(4) = 300: Points(5) = 400

    Points(6) = 400: Points(7) = 500

    Points(8) = 500: Points(9) = 600

    Call Polygon(hDC, Points(0), 5)

    MDraw1.hDC = True

End Sub


' Text Properties  Example

' The example creates two text object: horizontal and diagonal.

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control.  Then press F5.

Sub Form_Load ()

    MDraw1.AddItem "20 20", 10   ' OT_TEXT

    MDraw1.Text = "Horizontal text"

    MDraw1.TextHAlign = 0        ' Left

    MDraw1.TextVAlign = 0        ' Top

    MDraw1.FontName = "Arial"

    MDraw1.FontSize = 24         ' Size in points

    MDraw1.TextColor = 0

    MDraw1.AddItem "100 500", 10 ' OT_TEXT

    MDraw1.Text = "Diagonal text"

    MDraw1.TextHAlign = 2        ' Right

    MDraw1.TextVAlign = 1        ' Center

    MDraw1.FontName = "Times New Roman"

    MDraw1.FontSize = -150       ' Size in logic untits

    MDraw1.FontOrient = 30.5     ' Characters orientation

    MDraw1.TextColor = RGB(0, 0, 128)

End Sub


' Grid Properties  Example

' The example allows you to create an ellipse using the grid. To show/hide
' the grid press the "G" key, to toggle aligning to the grid press the "A" key.

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control (with a picture assigned to the
'  MouseCursor property).  Then press F5.

Dim SavePtr As Integer

Sub Form_Load ()
    MDraw1.AddItem "10 0", 10
    MDraw1.Text = "'G'     - Show grid"
    MDraw1.AddItem "10 50", 10
    MDraw1.Text = "'A'     - Align to grid"
    MDraw1.AddItem "10 100", 10
    MDraw1.Text = "'1'-'9' - Set grid size"
    MDraw1.AddItem "10 150", 10
    MDraw1.Text = "'Ctrl'  - Disable grid align"
    MDraw1.EditMode = 4
    SavePtr = -1
End Sub

Sub MDraw1_KeyDown (KeyCode As Integer, Shift As Integer)
    If (KeyCode = 17) And (SavePtr = -1) Then
      SavePtr = MDraw1.MousePointer
      MDraw1.MousePointer = 13
    End If
End Sub

Sub MDraw1_KeyPress (KeyAscii As Integer)
    Select Case KeyAscii
    Case 49 To 58       ' "1" - "9"
      MDraw1.GridWidth = (KeyAscii - 48) * 10
      MDraw1.GridHeight = (KeyAscii - 48) * 10
    Case 71, 103        ' "G", "g"
      MDraw1.GridShow = Not MDraw1.GridShow
    Case 65, 97         ' "A", "a"
      MDraw1.GridAlign = Not MDraw1.GridAlign
    End Select
    If MDraw1.GridShow Then

      MDraw1.MousePointer = IIf(MDraw1.GridAlign, 5, 2)

    Else

      MDraw1.MousePointer = IIf(MDraw1.GridAlign, 10, 0)

    End If

End Sub

Sub MDraw1_KeyUp (KeyCode As Integer, Shift As Integer)
    If (KeyCode = 17) And (SavePtr <> -1) Then
      MDraw1.MousePointer = SavePtr
      SavePtr = -1
    End If
End Sub


' Change object's parameters  Example

' The example creates three objects. The left mouse button click changes
' a shape for the polygon and sector objects. Click the right mouse button
' and drag the mouse to add new points to the polyline object.

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control. The project must include METADRAW.VBX
' and METADRAW.BAS files.  Then press F5 and click the control.

Dim Poly&, Pie&, PolyLine&

Sub Form_Load ()
    Dim NumPar As Integer, i%
    MDraw1.AutoScale = 1
    MDraw1.AddItem "100 100 600 600", OT_POLYGON
    Poly& = MDraw1.Current    ' Save handle
    NumPar = Int(Rnd * 100) + 3
    ReDim Points(NumPar) As VB_POINT
    For i% = 0 To NumPar
        Points(i%).x = Int(Rnd * 600)
        Points(i%).y = Int(Rnd * 500)
    Next i%
    Call MD_SetParams(MDraw1, 0, NumPar, Points(0), CRD_LOGIC)
    MDraw1.AddItem "700 450 950 700", OT_PIE
    Pie& = MDraw1.Current
    MDraw1.FillColor = RGB(255, 255, 0)
    MDraw1.AddItem "100 600 600 900", OT_POLYLINE
    PolyLine& = MDraw1.Current
    MDraw1.LineColor = RGB(0, 0, 128)
End Sub

Sub MDraw1_Click ()
    Dim NumPar As Integer, Fst As Integer, i%
    ReDim PtS(1) As VB_POINT
    MDraw1.Current = Poly&
    Call MD_GetParams(MDraw1, -1, NumPar, PtS(0), 0)
    ReDim Points(NumPar) As VB_POINT
    Fst = Int(Rnd * NumPar)
    NumPar = Int(Rnd * (NumPar - Fst)) + 1
    Call MD_GetParams(MDraw1, Fst, NumPar, Points(0), CRD_LOGIC)
    For i% = 0 To NumPar - 1
        Points(i%).x = 600 - Points(i%).x
        Points(i%).y = 500 - Points(i%).y
    Next i%
    Call MD_SetParams(MDraw1, Fst, NumPar, Points(0), CRD_LOGIC)

    MDraw1.Current = Pie&
    NumPar = 2
    PtS(0).x = Int(Rnd * MDraw1.picWidth)
    PtS(0).y = Int(Rnd * MDraw1.picHeight)
    PtS(1).x = Int(Rnd * MDraw1.picWidth)
    PtS(1).y = Int(Rnd * MDraw1.picHeight)
    Call MD_SetParams(MDraw1, 0, NumPar, PtS(0), CRD_LOGIC)
End Sub

Sub MDraw1_MouseMove (Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim Pt As VB_POINT, Num%
    If Button = 2 Then
        MDraw1.Current = PolyLine&
        Num% = 1
        Pt.x = x / Screen.TwipsPerPixelX
        Pt.y = y / Screen.TwipsPerPixelY
        Call MD_SetParams(MDraw1, -1, Num%, Pt, CRD_PIXELS + CRD_ADD)
    End If
End Sub


' Import/Export objects  Example

' The example shows how you can import or export objects using the clipboard.

' To try this example, paste the code into the Declarations section of a form
' that contains a MetaDraw control. The project must include METADRAW.VBX
' and METADRAW.BAS files.  Then press F5.

Dim PicType&
Dim DeltaX As Integer, DeltaY As Integer

Sub SetPicType ()
    MDraw1.Current = PicType&
    Select Case MDraw1.PictureType
    Case PICTYPE_METAFILE
      MDraw1.Text = "METAFILE"
    Case PICTYPE_BITMAP
      MDraw1.Text = "BITMAP"
    End Select
    MDraw1.Text = "PictureType: " & MDraw1.Text
End Sub

Sub Form_Load ()
    Dim i%, s$, cnt&
    Randomize
    MDraw1.AddItem "", OT_CONTAINER
    cnt& = MDraw1.Current
    For i% = 1 To 10
      s$ = Int(Rnd * 1000) & " " & Int(Rnd * 1000) & " "
      s$ = s$ & Int(Rnd * 1000) & " " & Int(Rnd * 1000)
      MDraw1.AddItem s$, Int(Rnd * 6) + 1
      MDraw1.FillColor = Int(Rnd * &HFFFFFF)
      MDraw1.LineColor = Int(Rnd * &HFFFFFF)
      MDraw1.LineWidth = Int(Rnd * 10)
    Next i%
    MDraw1.Current = OBJ_CONTAINER
    MDraw1.ObjOpened = False

    MDraw1.Current = OBJ_CURR_ATTR
    MDraw1.FontSize = -45       ' Change default font size
    MDraw1.FontName = "Arial"   ' and name
    MDraw1.AddItem "", OT_CONTAINER
    MDraw1.AddItem "280 0", 10
    PicType& = MDraw1.Current
    MDraw1.AddItem "10 0", 10
    MDraw1.Text = "'M' - MetaFile"
    MDraw1.AddItem "10 50", 10
    MDraw1.Text = "'B' - Bitmap"
    MDraw1.AddItem "10 700", 10
    MDraw1.Text = "'R' - Toggle paint mode"
    MDraw1.AddItem "10 750", 10
    MDraw1.Text = "'H' - Toggle Hints"
    MDraw1.AddItem "10 850", 10
    MDraw1.Text = "'S' - save picture to clipboard"
    MDraw1.AddItem "10 900", 10
    MDraw1.Text = "'C' - copy selected object(s) to clipboard  "
    MDraw1.AddItem "10 950", 10
    MDraw1.Text = "'P' - Paste object(s) from clipboard"
    MDraw1.Current = cnt
    MDraw1.ObjOpened = True
    MDraw1.OpenDraw = OPDR_FULL       ' Draw full picture
    MDraw1.Repaint = PAINT_BUFFERED   ' Use buffer
    MDraw1.AutoScale = 1
    MDraw1.EditMode = 11
    DeltaX = 50: DeltaY = 50
    Call SetPicType
End Sub

Sub MDraw1_KeyPress (KeyAscii As Integer)
    Select Case KeyAscii
    Case 77, 109    ' M, m
        MDraw1.PictureType = PICTYPE_METAFILE
        Call SetPicType
    Case 66, 98     ' B, b
        MDraw1.PictureType = PICTYPE_BITMAP
        Call SetPicType
    Case 80, 112    ' P, p
        Dim ofsX%, ofsY%
        MDraw1.PictureClip = Clipboard.GetData()
        ofsX% = DeltaX: ofsY% = DeltaY
        Call MD_MoveObjects(MDraw1, ofsX%, ofsY%, CRD_CHANGE)
        Clipboard.SetData MDraw1.PictureClip
        If ofsX% <> DeltaX Then DeltaX = -DeltaX
        If ofsY% <> DeltaY Then DeltaY = -DeltaY
    Case 67, 99     ' C, c
        MDraw1.Current = OBJ_SELECTED
        Clipboard.SetData MDraw1.PictureClip
    Case 83, 115     ' S, s
        MDraw1.Current = OBJ_CONTAINER
        MDraw1.ObjSelected = True
        MDraw1.Current = OBJ_SELECTED
        MDraw1.Action = ACT_GROUP
        Clipboard.SetData MDraw1.PictureClip
        MDraw1.Action = ACT_UNGROUP
        MDraw1.Current = OBJ_CONTAINER
        MDraw1.ObjSelected = False
    Case 72, 104     ' H, h
        If MDraw1.OpenDraw = OPDR_FULL Then
          MDraw1.OpenDraw = OPDR_CONTAINER
        Else
          MDraw1.OpenDraw = OPDR_FULL
        End If
        MDraw1.Current = OBJ_SELECTED
        Clipboard.SetData MDraw1.PictureClip
    Case 82, 114     ' R, r
        If MDraw1.Repaint = PAINT_NORMAL Then
          MDraw1.Repaint = PAINT_BUFFERED
        Else
          MDraw1.Repaint = PAINT_NORMAL
        End If

        If MDraw1.EditFlags And (Not EFLG_DRAWSCEL) Then
          MDraw1.EditFlags = MDraw1.EditFlags - EFLG_DRAWSCEL
        Else
          MDraw1.EditFlags = MDraw1.EditFlags + EFLG_DRAWSCEL
        End If
    Case 32
        If MDraw1.ObjCount(OBJ_SELECTED) > 0 Then
          MDraw1.RemoveItem OBJ_SELECTED
        End If
    End Select
End Sub


' There is no example for this property.


About the Bennet-Tec's products
About the product

This product is copyrighted by

(C) Bennet-Tec Information Systems, 1995

Software was written by

Gennady Petrov

Contact Information:

Bennet-Tec Information Systems,

10 Steuben Drive, Jericho, NY 11753

Phone (516) 433-6283

Fax (516) 979-6829

E-Mail: 71201.1075@Compuserve.Com

See also

List of VBXes from Bennet-Tec


About Jeff Bennett
	Jeff Bennett,  President and Founder of Bennet-Tec Bennet-Tec is a provider of Customized Software Solutions. Specializing in: Windows Programming, DOS to Windows Conversions, Dos and Windows Database Design, Visual Basic Custom Controls (VBX's).


About Gennady Petrov
Gennady Petrov, programmer.


Other VBX modules from Bennet-Tec
List of VBX modules from Bennet-Tec

ALLText is a multiple font text box, supporting the simultaneous display of multiple fonts, font characteristics and colors; paragraph formatting; and even inclusion of a bit mapped images as the background to the control. Using ALLText, you can include a WYSIWYG edit/display text box as part of your Visual Basic programs. The ability to highlight with colors as well as font characteristics make it the ideal choice for use in word-processing and hypertext applications.

PicScroll control allows the user to view a bitmap or metafile, resize the picture and scroll its visible part in a number of ways (by dragging with the mouse, using the optional scrollbars, or from the program). Using PicScroll as a container control, you can easily create scrollable/resizable data entry forms without the need to explicitly reposition every control from the program. The PicScroll's metafile support allows you to create and view metafiles of any size and complexity.

VBX Artist is the painting control that is able to draw (as a pencil, spray, eraser etc.) on the device context of any (or given) window while being dragged over it. VBX Artist recognizes and works with the PicScroll control, painting directly on its Picture property rather than on the device context. With PicScroll and VBX Artist, creating a painting program is a snap with just a few lines of code (you can build both bitmap-oriented or metafile-oriented drawing application).

Palette control (distributed with PicScroll and VBX Artist). Displays a logical palette and provides several ways to change/add colors.

DragDrop control converts between Visual Basic and File Manager drag & drop styles allowing to drag file names between VB and other applications. Together with the FileIcon control it provides an easy way to create your own Program Manager or File Manager like applications.

FileIcon control uses the Windows' Shell API functions to display the icon and (when clicked) to activate any document, help file or application associated with this control. FileIcon also accepts dropped files and can be used as a convenient destination point in a drag&drop based application.

Plot3D control allows the user to construct three-dimensional pictures from points and lines (optionally marked with colors or characters) and shows them from different points of view. The picture can also be rotated or zoomed fast and the user can select the particular groups of points and lines by the mouse marker. The Plot3D control is especially useful for statistical or other math applications.

CommonVar control allows the user to create a set of named common variables which could be accessed from within any application using this control. The use of common variables allows applications to exchange data between them much simpler than with the use of DDE protocol. The whole set of variables could be saved and restored to/from file. Additionaly, there are API specifications which allow to access common variables from any applications written in C, Pascal or other Windows-oriented languages.

TLIST control allows the user to apply a pictures, colored and multifonted text in the listbox control. This control allows to show the hierarchy of the items of the listbox. Moreover, with help of this control the user can easily create simple Toolbox control.

RULERS - HRuler and VRuler controls present Horizontal and Vertical Rulers for use in any VB application.  Measurements can be displayed in a variety of physical or logical units. Rulers can include pictures such as for TabStops, Indents, Margins, etc.

MetaDRAW control allows the user to create and edit pictures represented as a set of graphical elements, manipulate them (change attributes, positions and so on) programmatically or by the mouse. This control can load/save pictures or any part of its from/to metafiles or bitmaps. Also, MetaDRAW control is helpful for creating hypergraphical applications and animations.


[About] Property
[About]

See Also: About this Product

Description

At design time you can doubleclick this property in the property window to popup the About box with some copyright information. The [About] property doesn't carry any value and is not available at runtime.

Usage

none

Value

none


TWIPS are used in VB as a standard units of length: 1 TWIP = 1/1440 inch